Skip to content

Commit

Permalink
Merge pull request #33265 from DylanDylann/fix/32388-selected-dropdow…
Browse files Browse the repository at this point in the history
…n-item-with-tab-key-is-not-opened

Fix: focusing on item by tab key does not work
  • Loading branch information
deetergp authored Dec 21, 2023
2 parents 0a6c4e7 + ce0500f commit d3adb4f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/components/OptionRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ const propTypes = {
/** Whether to wrap large text up to 2 lines */
isMultilineSupported: PropTypes.bool,

/** Key used internally by React */
keyForList: PropTypes.string,
style: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.object), PropTypes.object]),

...withLocalizePropTypes,
Expand All @@ -99,6 +101,7 @@ const defaultProps = {
shouldHaveOptionSeparator: false,
shouldDisableRowInnerPadding: false,
shouldPreventDefaultFocusOnSelectRow: false,
keyForList: undefined,
};

function OptionRow(props) {
Expand Down Expand Up @@ -162,6 +165,7 @@ function OptionRow(props) {
<Hoverable>
{(hovered) => (
<PressableWithFeedback
testID={props.keyForList}
ref={(el) => (pressableRef.current = el)}
onPress={(e) => {
if (!props.onSelectRow) {
Expand Down
1 change: 1 addition & 0 deletions src/components/OptionsList/BaseOptionsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ function BaseOptionsList({

return (
<OptionRow
keyForList={item.keyForList}
option={item}
showTitleTooltip={showTitleTooltip}
hoverStyle={optionHoveredStyle}
Expand Down
5 changes: 3 additions & 2 deletions src/components/OptionsSelector/BaseOptionsSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,9 @@ class BaseOptionsSelector extends Component {
}
}

selectFocusedOption() {
const focusedOption = this.state.allOptions[this.state.focusedIndex];
selectFocusedOption(e) {
const focusedItemKey = lodashGet(e, ['target', 'attributes', 'data-testid', 'value']);
const focusedOption = focusedItemKey ? _.find(this.state.allOptions, (option) => option.keyForList === focusedItemKey) : this.state.allOptions[this.state.focusedIndex];

if (!focusedOption || !this.props.isFocused) {
return;
Expand Down

0 comments on commit d3adb4f

Please sign in to comment.