Skip to content

Commit bbc4501

Browse files
authored
🐛 Fix treeRef.current.scrollTo throw error (#217)
when treeData is empty close ant-design/ant-design#21627
1 parent 310f332 commit bbc4501

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/OptionList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ const OptionList: React.RefForwardingComponent<
130130
React.useEffect(() => {
131131
// Single mode should scroll to current key
132132
if (open && !multiple && valueKeys.length) {
133-
treeRef.current.scrollTo({ key: valueKeys[0] });
133+
treeRef.current?.scrollTo({ key: valueKeys[0] });
134134
}
135135
}, [open]);
136136

tests/Select.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ describe('TreeSelect.basic', () => {
6767
mount(<TreeSelect open />);
6868
});
6969

70+
it('not crash if no treeData', () => {
71+
const wrapper = mount(<TreeSelect value="" treeData={[]} open />);
72+
});
73+
7074
it('renders disabled correctly', () => {
7175
const wrapper = mount(<TreeSelect disabled treeData={treeData} />);
7276
expect(wrapper.render()).toMatchSnapshot();

0 commit comments

Comments
 (0)