Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Autocomplete] Fix incorrect selected state in examples #1053

Merged
merged 1 commit into from
Feb 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f
- Added accessibility documentation for `InlineError` ([#1073](https://github.com/Shopify/polaris-react/pull/1073))
- Added accessibility documentation for `Loading`([#1075](https://github.com/Shopify/polaris-react/pull/1075))
- Fixed documentation about the `ariaPressed` prop for `Button` ([#1097](https://github.com/Shopify/polaris-react/pull/1097))
- Fixed examples using the `selected` prop for `Autocomplete` ([#1053](https://github.com/Shopify/polaris-react/pull/1053))

### Development workflow

Expand Down
34 changes: 16 additions & 18 deletions src/components/Autocomplete/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ class AutocompleteExample extends React.Component {
});
};

updateSelection = (updatedSelection) => {
const selectedText = updatedSelection.map((selectedItem) => {
const matchedOption = this.options.filter((option) => {
updateSelection = (selected) => {
const selectedText = selected.map((selectedItem) => {
const matchedOption = this.options.find((option) => {
return option.value.match(selectedItem);
});
return matchedOption[0] && matchedOption[0].label;
return matchedOption && matchedOption.label;
});
this.setState({selected: selectedText, inputText: selectedText});
this.setState({selected, inputText: selectedText});
};
}
```
Expand Down Expand Up @@ -202,9 +202,7 @@ class MultiAutocompleteExample extends React.Component {
});
};

updateSelection = (updatedSelection) => {
this.setState({selected: updatedSelection});
};
updateSelection = (selected) => this.setState({selected});
}

function titleCase(string) {
Expand Down Expand Up @@ -291,14 +289,14 @@ class AutocompleteExample extends React.Component {
}, 300);
};

updateSelection = (updatedSelection) => {
const selectedText = updatedSelection.map((selectedItem) => {
const matchedOption = this.options.filter((option) => {
updateSelection = (selected) => {
const selectedText = selected.map((selectedItem) => {
const matchedOption = this.options.find((option) => {
return option.value.match(selectedItem);
});
return matchedOption[0] && matchedOption[0].label;
return matchedOption && matchedOption.label;
});
this.setState({selected: selectedText, inputText: selectedText});
this.setState({selected, inputText: selectedText});
};
}
```
Expand Down Expand Up @@ -385,14 +383,14 @@ class AutocompleteExample extends React.Component {
}, 300);
};

updateSelection = (updatedSelection) => {
const selectedText = updatedSelection.map((selectedItem) => {
const matchedOption = this.options.filter((option) => {
updateSelection = (selected) => {
const selectedText = selected.map((selectedItem) => {
const matchedOption = this.options.find((option) => {
return option.value.match(selectedItem);
});
return matchedOption[0] && matchedOption[0].label;
return matchedOption && matchedOption.label;
});
this.setState({selected: selectedText, inputText: selectedText});
this.setState({selected, inputText: selectedText});
};
}
```
Expand Down