Skip to content

Commit

Permalink
Merge pull request #2753 from JedWatson/v2-hide-selected-default
Browse files Browse the repository at this point in the history
V2 hide selected default
  • Loading branch information
JedWatson committed Jun 27, 2018
2 parents 9b1cc2c + f84612d commit 9c5e84f
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 28 deletions.
12 changes: 8 additions & 4 deletions src/Select.js
Expand Up @@ -203,7 +203,6 @@ export const defaultProps = {
formatGroupLabel: formatGroupLabel,
getOptionLabel: getOptionLabel,
getOptionValue: getOptionValue,
hideSelectedOptions: true,
isDisabled: false,
isLoading: false,
isMulti: false,
Expand Down Expand Up @@ -854,6 +853,11 @@ export default class Select extends Component<Props, State> {
}
this.setState({ focusedOption });
};
shouldHideSelectedOptions = () => {
const { hideSelectedOptions, isMulti } = this.props;
if (hideSelectedOptions === undefined) return isMulti;
return hideSelectedOptions;
};

// ==============================
// Keyboard Handlers
Expand Down Expand Up @@ -986,7 +990,7 @@ export default class Select extends Component<Props, State> {
// ==============================

buildMenuOptions(props: Props, selectValue: OptionsType): MenuOptions {
const { hideSelectedOptions, isMulti, inputValue = '', options } = props;
const { inputValue = '', options } = props;

const toOption = (option, id) => {
const isDisabled = this.isOptionDisabled(option);
Expand All @@ -995,7 +999,7 @@ export default class Select extends Component<Props, State> {
const value = this.getOptionValue(option);

if (
(isMulti && hideSelectedOptions && isSelected) ||
(this.shouldHideSelectedOptions() && isSelected) ||
!this.filterOption({ label, value, data: option }, inputValue)
) {
return;
Expand Down Expand Up @@ -1196,7 +1200,7 @@ export default class Select extends Component<Props, State> {
</MultiValue>
);
});
return selectValues;
return selectValues;
}

if (inputValue) {
Expand Down
8 changes: 0 additions & 8 deletions src/__tests__/__snapshots__/Async.test.js.snap
Expand Up @@ -33,7 +33,6 @@ exports[`defaults - snapshot 1`] = `
formatGroupLabel={[Function]}
getOptionLabel={[Function]}
getOptionValue={[Function]}
hideSelectedOptions={true}
inputValue=""
isDisabled={false}
isLoading={false}
Expand Down Expand Up @@ -101,7 +100,6 @@ exports[`defaults - snapshot 1`] = `
"formatGroupLabel": [Function],
"getOptionLabel": [Function],
"getOptionValue": [Function],
"hideSelectedOptions": true,
"inputValue": "",
"isDisabled": false,
"isLoading": false,
Expand Down Expand Up @@ -191,7 +189,6 @@ exports[`defaults - snapshot 1`] = `
"formatGroupLabel": [Function],
"getOptionLabel": [Function],
"getOptionValue": [Function],
"hideSelectedOptions": true,
"inputValue": "",
"isDisabled": false,
"isLoading": false,
Expand Down Expand Up @@ -260,7 +257,6 @@ exports[`defaults - snapshot 1`] = `
"formatGroupLabel": [Function],
"getOptionLabel": [Function],
"getOptionValue": [Function],
"hideSelectedOptions": true,
"inputValue": "",
"isDisabled": false,
"isLoading": false,
Expand Down Expand Up @@ -328,7 +324,6 @@ exports[`defaults - snapshot 1`] = `
"formatGroupLabel": [Function],
"getOptionLabel": [Function],
"getOptionValue": [Function],
"hideSelectedOptions": true,
"inputValue": "",
"isDisabled": false,
"isLoading": false,
Expand Down Expand Up @@ -517,7 +512,6 @@ exports[`defaults - snapshot 1`] = `
"formatGroupLabel": [Function],
"getOptionLabel": [Function],
"getOptionValue": [Function],
"hideSelectedOptions": true,
"inputValue": "",
"isDisabled": false,
"isLoading": false,
Expand Down Expand Up @@ -590,7 +584,6 @@ exports[`defaults - snapshot 1`] = `
"formatGroupLabel": [Function],
"getOptionLabel": [Function],
"getOptionValue": [Function],
"hideSelectedOptions": true,
"inputValue": "",
"isDisabled": false,
"isLoading": false,
Expand Down Expand Up @@ -667,7 +660,6 @@ exports[`defaults - snapshot 1`] = `
"formatGroupLabel": [Function],
"getOptionLabel": [Function],
"getOptionValue": [Function],
"hideSelectedOptions": true,
"inputValue": "",
"isDisabled": false,
"isLoading": false,
Expand Down
8 changes: 0 additions & 8 deletions src/__tests__/__snapshots__/AsyncCreatable.test.js.snap
Expand Up @@ -59,7 +59,6 @@ exports[`defaults - snapshot 1`] = `
getNewOptionData={[Function]}
getOptionLabel={[Function]}
getOptionValue={[Function]}
hideSelectedOptions={true}
inputValue=""
isDisabled={false}
isLoading={false}
Expand Down Expand Up @@ -132,7 +131,6 @@ exports[`defaults - snapshot 1`] = `
"getNewOptionData": [Function],
"getOptionLabel": [Function],
"getOptionValue": [Function],
"hideSelectedOptions": true,
"inputValue": "",
"isDisabled": false,
"isLoading": false,
Expand Down Expand Up @@ -227,7 +225,6 @@ exports[`defaults - snapshot 1`] = `
"getNewOptionData": [Function],
"getOptionLabel": [Function],
"getOptionValue": [Function],
"hideSelectedOptions": true,
"inputValue": "",
"isDisabled": false,
"isLoading": false,
Expand Down Expand Up @@ -301,7 +298,6 @@ exports[`defaults - snapshot 1`] = `
"getNewOptionData": [Function],
"getOptionLabel": [Function],
"getOptionValue": [Function],
"hideSelectedOptions": true,
"inputValue": "",
"isDisabled": false,
"isLoading": false,
Expand Down Expand Up @@ -374,7 +370,6 @@ exports[`defaults - snapshot 1`] = `
"getNewOptionData": [Function],
"getOptionLabel": [Function],
"getOptionValue": [Function],
"hideSelectedOptions": true,
"inputValue": "",
"isDisabled": false,
"isLoading": false,
Expand Down Expand Up @@ -568,7 +563,6 @@ exports[`defaults - snapshot 1`] = `
"getNewOptionData": [Function],
"getOptionLabel": [Function],
"getOptionValue": [Function],
"hideSelectedOptions": true,
"inputValue": "",
"isDisabled": false,
"isLoading": false,
Expand Down Expand Up @@ -646,7 +640,6 @@ exports[`defaults - snapshot 1`] = `
"getNewOptionData": [Function],
"getOptionLabel": [Function],
"getOptionValue": [Function],
"hideSelectedOptions": true,
"inputValue": "",
"isDisabled": false,
"isLoading": false,
Expand Down Expand Up @@ -728,7 +721,6 @@ exports[`defaults - snapshot 1`] = `
"getNewOptionData": [Function],
"getOptionLabel": [Function],
"getOptionValue": [Function],
"hideSelectedOptions": true,
"inputValue": "",
"isDisabled": false,
"isLoading": false,
Expand Down
7 changes: 0 additions & 7 deletions src/__tests__/__snapshots__/Select.test.js.snap
Expand Up @@ -32,7 +32,6 @@ exports[`snapshot - defaults 1`] = `
"formatGroupLabel": [Function],
"getOptionLabel": [Function],
"getOptionValue": [Function],
"hideSelectedOptions": true,
"isDisabled": false,
"isLoading": false,
"isMulti": false,
Expand Down Expand Up @@ -100,7 +99,6 @@ exports[`snapshot - defaults 1`] = `
"formatGroupLabel": [Function],
"getOptionLabel": [Function],
"getOptionValue": [Function],
"hideSelectedOptions": true,
"isDisabled": false,
"isLoading": false,
"isMulti": false,
Expand Down Expand Up @@ -153,7 +151,6 @@ exports[`snapshot - defaults 1`] = `
"formatGroupLabel": [Function],
"getOptionLabel": [Function],
"getOptionValue": [Function],
"hideSelectedOptions": true,
"isDisabled": false,
"isLoading": false,
"isMulti": false,
Expand Down Expand Up @@ -207,7 +204,6 @@ exports[`snapshot - defaults 1`] = `
"formatGroupLabel": [Function],
"getOptionLabel": [Function],
"getOptionValue": [Function],
"hideSelectedOptions": true,
"isDisabled": false,
"isLoading": false,
"isMulti": false,
Expand Down Expand Up @@ -285,7 +281,6 @@ exports[`snapshot - defaults 1`] = `
"formatGroupLabel": [Function],
"getOptionLabel": [Function],
"getOptionValue": [Function],
"hideSelectedOptions": true,
"isDisabled": false,
"isLoading": false,
"isMulti": false,
Expand Down Expand Up @@ -344,7 +339,6 @@ exports[`snapshot - defaults 1`] = `
"formatGroupLabel": [Function],
"getOptionLabel": [Function],
"getOptionValue": [Function],
"hideSelectedOptions": true,
"isDisabled": false,
"isLoading": false,
"isMulti": false,
Expand Down Expand Up @@ -405,7 +399,6 @@ exports[`snapshot - defaults 1`] = `
"formatGroupLabel": [Function],
"getOptionLabel": [Function],
"getOptionValue": [Function],
"hideSelectedOptions": true,
"isDisabled": false,
"isLoading": false,
"isMulti": false,
Expand Down
1 change: 0 additions & 1 deletion src/__tests__/__snapshots__/StateManaged.test.js.snap
Expand Up @@ -16,7 +16,6 @@ exports[`defaults > snapshot 1`] = `
formatGroupLabel={[Function]}
getOptionLabel={[Function]}
getOptionValue={[Function]}
hideSelectedOptions={true}
inputValue=""
isDisabled={false}
isLoading={false}
Expand Down

0 comments on commit 9c5e84f

Please sign in to comment.