Skip to content

Commit 57a1793

Browse files
EmilyyyLiu刘欢
andauthored
feat: Panel use optionRender (#618)
Co-authored-by: 刘欢 <[email protected]>
1 parent 3176b77 commit 57a1793

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/Panel.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ export type PickType =
3636
| 'style'
3737
| 'direction'
3838
| 'notFoundContent'
39-
| 'disabled';
39+
| 'disabled'
40+
| 'optionRender';
4041

4142
export type PanelProps<
4243
OptionType extends DefaultOptionType = DefaultOptionType,
@@ -70,6 +71,7 @@ export default function Panel<
7071
direction,
7172
notFoundContent = 'Not Found',
7273
disabled,
74+
optionRender,
7375
} = props as Pick<InternalCascaderProps, PickType>;
7476

7577
// ======================== Multiple ========================
@@ -159,6 +161,7 @@ export default function Panel<
159161
expandIcon,
160162
loadingIcon,
161163
popupMenuColumnStyle: undefined,
164+
optionRender
162165
}),
163166
[
164167
mergedOptions,
@@ -172,6 +175,7 @@ export default function Panel<
172175
expandTrigger,
173176
expandIcon,
174177
loadingIcon,
178+
optionRender,
175179
],
176180
);
177181

tests/Panel.spec.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,25 @@ describe('Cascader.Panel', () => {
110110
fireEvent.click(selectOption);
111111
expect(onChange).not.toHaveBeenCalled();
112112
});
113+
114+
it('Should optionRender work in Panel', () => {
115+
const { container, rerender } = render(
116+
<Cascader.Panel
117+
options={[{ label: 'bamboo', value: 'bamboo' }]}
118+
optionRender={option => `${option.label} - test`}
119+
/>,
120+
);
121+
expect(container.querySelector('.rc-cascader-menu-item-content')?.innerHTML).toEqual(
122+
'bamboo - test',
123+
);
124+
rerender(
125+
<Cascader.Panel
126+
options={[{ label: 'bamboo', disabled: true, value: 'bamboo' }]}
127+
optionRender={option => JSON.stringify(option)}
128+
/>,
129+
);
130+
expect(container.querySelector('.rc-cascader-menu-item-content')?.innerHTML).toEqual(
131+
'{"label":"bamboo","disabled":true,"value":"bamboo"}',
132+
);
133+
});
113134
});

0 commit comments

Comments
 (0)