Skip to content

Commit

Permalink
Merge branch 'master' into #3006-Documentation-Additions-and-Revisions
Browse files Browse the repository at this point in the history
  • Loading branch information
JedWatson authored Jan 13, 2021
2 parents 17680f6 + ef2d357 commit 9c4dec3
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/pink-cats-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"react-select": patch
---

Fixed value passed to onChange when clearing value
5 changes: 5 additions & 0 deletions .changeset/quick-carrots-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"react-select": patch
---

Base aria-live message on tabSelectsValue prop
28 changes: 21 additions & 7 deletions packages/react-select/src/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,11 @@ export default class Select extends Component<Props, State> {
this.focusInput();
}

if (isFocused && isDisabled && !prevProps.isDisabled) {
// ensure select state gets blurred in case Select is programatically disabled while focused
this.setState({ isFocused: false }, this.onMenuClose);
}

// scroll the focused option into view if necessary
if (
this.menuListRef &&
Expand Down Expand Up @@ -501,7 +506,7 @@ export default class Select extends Component<Props, State> {
openMenu(focusOption: 'first' | 'last') {
const { selectValue, isFocused } = this.state;
const menuOptions = this.buildMenuOptions(this.props, selectValue);
const { isMulti } = this.props;
const { isMulti, tabSelectsValue } = this.props;
let openAtIndex =
focusOption === 'first' ? 0 : menuOptions.focusable.length - 1;

Expand All @@ -524,7 +529,10 @@ export default class Select extends Component<Props, State> {
},
() => {
this.onMenuOpen();
this.announceAriaLiveContext({ event: 'menu' });
this.announceAriaLiveContext({
event: 'menu',
context: { tabSelectsValue },
});
}
);
}
Expand Down Expand Up @@ -582,7 +590,7 @@ export default class Select extends Component<Props, State> {
}

focusOption(direction: FocusDirection = 'first') {
const { pageSize } = this.props;
const { pageSize, tabSelectsValue } = this.props;
const { focusedOption, menuOptions } = this.state;
const options = menuOptions.focusable;

Expand All @@ -591,7 +599,10 @@ export default class Select extends Component<Props, State> {
let focusedIndex = options.indexOf(focusedOption);
if (!focusedOption) {
focusedIndex = -1;
this.announceAriaLiveContext({ event: 'menu' });
this.announceAriaLiveContext({
event: 'menu',
context: { tabSelectsValue },
});
}

if (direction === 'up') {
Expand All @@ -614,7 +625,10 @@ export default class Select extends Component<Props, State> {
});
this.announceAriaLiveContext({
event: 'menu',
context: { isDisabled: isOptionDisabled(options[nextFocus]) },
context: {
isDisabled: isOptionDisabled(options[nextFocus]),
tabSelectsValue,
},
});
}
onChange = (newValue: ValueType, actionMeta: ActionMeta) => {
Expand Down Expand Up @@ -706,8 +720,7 @@ export default class Select extends Component<Props, State> {
this.focusInput();
};
clearValue = () => {
const { isMulti } = this.props;
this.onChange(isMulti ? [] : null, { action: 'clear' });
this.onChange(null, { action: 'clear' });
};
popValue = () => {
const { selectValue } = this.state;
Expand Down Expand Up @@ -1715,6 +1728,7 @@ export default class Select extends Component<Props, State> {
Heading={GroupHeading}
headingProps={{
id: headingId,
data: item.data,
}}
label={this.formatGroupLabel(item.data)}
>
Expand Down
2 changes: 1 addition & 1 deletion packages/react-select/src/__tests__/Select.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2305,7 +2305,7 @@ test('clear select by clicking on clear button > should not call onMenuOpen', ()
container.querySelector('.react-select__clear-indicator'),
{ button: 0 }
);
expect(onChangeSpy).toBeCalledWith([], {
expect(onChangeSpy).toBeCalledWith(null, {
action: 'clear',
name: BASIC_PROPS.name,
});
Expand Down
9 changes: 7 additions & 2 deletions packages/react-select/src/accessibility/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,24 @@ export type InstructionsContext = {
isMulti?: boolean,
label?: string,
isDisabled?: boolean,
tabSelectsValue?: boolean,
};
export type ValueEventContext = { value: string, isDisabled?: boolean };

export const instructionsAriaMessage = (
event: string,
context?: InstructionsContext = {}
) => {
const { isSearchable, isMulti, label, isDisabled } = context;
const { isSearchable, isMulti, label, isDisabled, tabSelectsValue } = context;
switch (event) {
case 'menu':
return `Use Up and Down to choose options${
isDisabled ? '' : ', press Enter to select the currently focused option'
}, press Escape to exit the menu, press Tab to select the option and exit the menu.`;
}, press Escape to exit the menu${
tabSelectsValue
? ', press Tab to select the option and exit the menu'
: ''
}.`;
case 'input':
return `${label ? label : 'Select'} is focused ${
isSearchable ? ',type to refine list' : ''
Expand Down

0 comments on commit 9c4dec3

Please sign in to comment.