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

UI x-radio: fix keyboard navigation when value of first/last radio option is null #4308

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

gdebrauwer
Copy link
Contributor

When the first or last x-radio:option has null as value, then keyboard navigation does not work correctly. It skips that option because it thinks that is already reached the end or beginning of the options array (caused by next || all[0] or prev || all.slice(-1)[0]). See screen recordings as a visual example.

Untitled2.mov
Untitled.mov

Copy link
Contributor

@ekwoka ekwoka left a comment

Choose a reason for hiding this comment

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

Interesting case!

Looks like most of this needs to be refactored...

Comment on lines 109 to 110
let index = all.indexOf(option)
let next = all.length > index + 1 ? all[index + 1] : all[0]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let index = all.indexOf(option)
let next = all.length > index + 1 ? all[index + 1] : all[0]
let index = all.indexOf(option)
let next = all[(index + 1 + all.length) % all.length]

Comment on lines 118 to 119
let index = all.indexOf(option)
let prev = index >= 1 ? all[all.indexOf(option) - 1] : all.slice(-1)[0]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let index = all.indexOf(option)
let prev = index >= 1 ? all[all.indexOf(option) - 1] : all.slice(-1)[0]
let index = all.indexOf(option)
let prev = all[(index - 1 + all.length) % all.length]

@gdebrauwer gdebrauwer requested a review from ekwoka July 19, 2024 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants