Esri / calcite-design-system

A monorepo containing the packages for Esri's Calcite Design System
https://developers.arcgis.com/calcite-design-system/
Other
282 stars 76 forks source link

Inputs inside list lose focus when arrow keys pressed #10271

Open nwhittaker opened 1 week ago

nwhittaker commented 1 week ago

Check existing issues

Actual Behavior

Given a list of list items that contain input elements: When an element has focus and the user presses an up or down arrow key, focus can shift to the next list item instead of performing the input's default behavior.

Expected Behavior

Focus is not shifted from the input and the input's default behavior is performed. In the case of text inputs, the cursor should move to the beginning or end of its value. For number inputs, the value should be incremented or decremented. Etc…

Reproduction Sample

https://codepen.io/nwhittaker-esri/pen/OJeqrJq

Reproduction Steps

  1. Visit the repro.
  2. Focus the first text input and hit either the up or down arrow key and see focus shifted away.
  3. Focus the second input and hit the down arrow key and see the value is decremented but focus is also shifted the next list item. Interestingly, hitting the up arrow key correctly increments the value without shifting focus to the previous list item.

Reproduction Version

2.12.2

Relevant Info

No response

Regression?

No response

Priority impact

impact - p2 - want for an upcoming milestone

Impact

A workaround is to ignore keyboard events on the list-item if the target is a descendant.

list.querySelector('calcite-list-item').addEventListener('keydown', event => {
  if (!event.target.matches('calcite-list-item')) {
    event.stopPropagation()
  }
})

However, this listener can't be delegated so it must be attached/detached to every list item. Which can become cumbersome for dynamically generated lists and easily lead to memory leaks.

Calcite package

Esri team

ArcGIS Field Apps

driskull commented 1 week ago

Input should be preventing default on ArrowDown just like it is on ArrowUp.