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

Fix: focusing on item by tab key does not work #33265

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
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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put this above style and provide a comment explaining it function as we do with other props

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alitoshmatov I just updated

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 @@ -163,6 +166,7 @@ function OptionRow(props) {
<Hoverable>
{(hovered) => (
<PressableWithFeedback
testID={props.keyForList}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticing that we probably shouldn't have used testID here since that's pretty much specifically used for testing, why didn't we use id or nativeID?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI we updated this in #33667

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 @@ -302,8 +302,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
Loading