Skip to content

Commit 3a0cd20

Browse files
authored
chore: rtl & empty (#431)
* chore: rtl & empty * test: add test case
1 parent ce84920 commit 3a0cd20

File tree

4 files changed

+48
-10
lines changed

4 files changed

+48
-10
lines changed

examples/panel.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ export default () => {
6767
console.log('Change:', value);
6868
}}
6969
/>
70+
71+
<Cascader.Panel options={addressOptions} direction="rtl" />
72+
73+
<Cascader.Panel notFoundContent="Empty!!!" />
7074
</>
7175
);
7276
};

examples/search.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const addressOptions = [
6969
class Demo extends React.Component {
7070
render() {
7171
return (
72-
<Cascader options={addressOptions} showSearch style={{ width: 300 }} animation="slide-up" />
72+
<Cascader options={addressOptions} showSearch style={{ width: 300 }} animation="slide-up" notFoundContent="Empty Content!" />
7373
);
7474
}
7575
}

src/Panel.tsx

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ export type PickType =
2626
| 'expandIcon'
2727
| 'loadingIcon'
2828
| 'className'
29-
| 'style';
29+
| 'style'
30+
| 'direction'
31+
| 'notFoundContent';
3032

3133
export type PanelProps = Pick<CascaderProps, PickType>;
3234

@@ -49,6 +51,8 @@ export default function Panel(props: PanelProps) {
4951
expandTrigger,
5052
expandIcon = '>',
5153
loadingIcon,
54+
direction,
55+
notFoundContent = 'Not Found',
5256
} = props as Pick<InternalCascaderProps, PickType>;
5357

5458
// ======================== Multiple ========================
@@ -155,16 +159,34 @@ export default function Panel(props: PanelProps) {
155159
);
156160

157161
// ========================= Render =========================
162+
const panelPrefixCls = `${prefixCls}-panel`;
163+
const isEmpty = !mergedOptions.length;
164+
158165
return (
159166
<CascaderContext.Provider value={cascaderContext}>
160-
<div className={classNames(`${prefixCls}-panel`, className)} style={style}>
161-
<RawOptionList
162-
prefixCls={prefixCls}
163-
searchValue={null}
164-
multiple={multiple}
165-
toggleOpen={noop}
166-
open
167-
/>
167+
<div
168+
className={classNames(
169+
panelPrefixCls,
170+
{
171+
[`${panelPrefixCls}-rtl`]: direction === 'rtl',
172+
[`${panelPrefixCls}-empty`]: isEmpty,
173+
},
174+
className,
175+
)}
176+
style={style}
177+
>
178+
{isEmpty ? (
179+
notFoundContent
180+
) : (
181+
<RawOptionList
182+
prefixCls={prefixCls}
183+
searchValue={null}
184+
multiple={multiple}
185+
toggleOpen={noop}
186+
open
187+
direction={direction}
188+
/>
189+
)}
168190
</div>
169191
</CascaderContext.Provider>
170192
);

tests/Panel.spec.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,16 @@ describe('Cascader.Panel', () => {
8080
fireEvent.click(container.querySelectorAll('.rc-cascader-checkbox')[1]);
8181
expect(onChange).toHaveBeenCalledWith([['bamboo', 'little']], expect.anything());
8282
});
83+
84+
it('rtl', () => {
85+
const { container } = render(<Cascader.Panel options={options} direction="rtl" />);
86+
87+
expect(container.querySelector('.rc-cascader-panel-rtl')).toBeTruthy();
88+
});
89+
90+
it('notFoundContent', () => {
91+
const { container } = render(<Cascader.Panel notFoundContent="Hello World" />);
92+
93+
expect(container.querySelector('.rc-cascader-panel-empty').textContent).toEqual('Hello World');
94+
});
8395
});

0 commit comments

Comments
 (0)