Skip to content

Commit

Permalink
fix(Select): adjust auto-complete menu length issue, close alibaba-fu…
Browse files Browse the repository at this point in the history
  • Loading branch information
zizairufengLT committed Aug 16, 2024
1 parent b300a60 commit 21f9e3a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
11 changes: 10 additions & 1 deletion components/select/__tests__/index-spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ describe('AutoComplete', () => {
visible: true,
});
cy.get('input').should('have.value', 'yyy');
cy.get('.next-menu-item').should('have.length', 2);
cy.get('.next-menu-item').should('have.length', 1);
});

it('should support empty value from dataSource', () => {
Expand Down Expand Up @@ -1084,6 +1084,15 @@ describe('AutoComplete', () => {
});
});

it('should render currect dataSource when value changed', () => {
cy.rerender('Demo', {
value: undefined,
visible: true,
});
cy.get('input').should('have.value', '');
cy.get('.next-menu-item').should('have.length', 2);
});

describe('react api', () => {
it('calls componentWillReceiveProps', () => {
cy.rerender('Demo', { value: '30' });
Expand Down
6 changes: 5 additions & 1 deletion components/select/auto-complete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ class AutoComplete extends Base<AutoCompleteProps, AutoCompleteState> {
const props = this.props;

if ('value' in props) {
this.dataStore.setOptions({ key: props.value });
if (prevProps.value !== props.value) {
this.setState({
dataSource: this.dataStore.updateByKey(props.value),
});
}
}

if (props.filter !== prevProps.filter) {
Expand Down
2 changes: 1 addition & 1 deletion components/select/data-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class DataStore {
return this.updateAll();
}

updateByKey(key: string) {
updateByKey(key?: string | number | null) {
if (key === this.options.key) {
return this.getMenuDS();
}
Expand Down

0 comments on commit 21f9e3a

Please sign in to comment.