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

MultiSelect/ListBox: KeyA is 'q' on azerty keeboard #7130

Closed
Et7f3 opened this issue Sep 7, 2024 · 7 comments · Fixed by #7214
Closed

MultiSelect/ListBox: KeyA is 'q' on azerty keeboard #7130

Et7f3 opened this issue Sep 7, 2024 · 7 comments · Fixed by #7214
Assignees
Labels
Type: Bug Issue contains a defect related to a specific component.
Milestone

Comments

@Et7f3
Copy link
Contributor

Et7f3 commented Sep 7, 2024

Describe the bug

The bug is this line

if (props.multiple && event.code === 'KeyA' && metaKey) {

const value = visibleOptions.filter((option) => isValidOption(option)).map((option) => getOptionValue(option));

Here it is the event object:
image

Reproducer

Just use any example in the documentation

System Information

N/A

Steps to reproduce the behavior

  1. Take physical qwerty keyboard
  2. Change keyboard layout to azerty
  3. Go to https://primereact.org/listbox/#multiple
  4. Click on one item
  5. press meta+a (so the physical key with label q on the physical keyboard) and nothing is selected
  6. press meta+q (so the physical key with label a on the physical keyboard) all is selected

Expected behavior

The shortcut should execute when the key labeled A is triggered.

@Et7f3 Et7f3 added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Sep 7, 2024
@melloware
Copy link
Member

@Et7f3 do you have a solution?

@melloware melloware added Type: Bug Issue contains a defect related to a specific component. and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Sep 7, 2024
@sja-cslab
Copy link
Contributor

sja-cslab commented Sep 9, 2024

@melloware KeyboardEvent.key should be used.

MDN says:

For example, the code returned is "KeyQ" for the Q key on a QWERTY layout keyboard, but the same code value also represents the ' key on Dvorak keyboards and the A key on AZERTY keyboards. That makes it impossible to use the value of code to determine what the name of the key is to users if they're not using an anticipated keyboard layout.

To determine what character corresponds with the key event, use the KeyboardEvent.key property instead.

@melloware
Copy link
Member

@sja-cslab can you submit a PR?

@sja-cslab
Copy link
Contributor

If I find time - just back from vacation today so I've to catch 3 weeks of work :/

@Et7f3
Copy link
Contributor Author

Et7f3 commented Sep 11, 2024

do you have a solution?

Yes I showed the event object that hinted we should use .key and @sja-cslab confirmed it is the right choice. So I let him open a PR (I won't be able to open one before october).

My quickfix is a call to sed that replace KeyA by KeyQ in my node_modules (because my users have azerty layout). I can live with this workaround so no rush in implementing a fix.

@sja-cslab
Copy link
Contributor

sja-cslab commented Sep 12, 2024

@melloware we may need to discuss if we just want to fix the condition

if (props.multiple && event.code === 'KeyA' && metaKey) {

or if we want to change the whole handling in that component. One point we need to keep in mind is, that .key works a bit different than .code in case of the keys itself.

a e.g. is event.key === "a" where shift+a would be event.key === "A"

The KeyboardEvent interface's key read-only property returns the value of the key pressed by the user, taking into consideration the state of modifier keys such as Shift as well as the keyboard locale and layout.

I'm not sure if it's a good or a bad idea if we would combine .key and .metaKey / .ctrlKey
Found an example in MDN which uses combination of both.

@melloware
Copy link
Member

Yes we typically try and use event.code when possible and event.key when necessary. Its OK to use event.key in this specific case.

@melloware melloware added this to the 10.8.4 milestone Sep 18, 2024
melloware pushed a commit that referenced this issue Sep 18, 2024
…ems on azerty layouts (#7214)

* Update ListBox.js

* Update MultiSelect.js replace keycode with key
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a defect related to a specific component.
Projects
None yet
3 participants