Unable to set custom focus after selecting a dropdown-item #10821
Labels
0 - new
New issues that need assignment.
ArcGIS Field Apps
Issues logged by ArcGIS Field Apps team members.
bug
Bug reports for broken functionality. Issues should include a reproduction of the bug.
calcite-components
Issues specific to the @esri/calcite-components package.
impact - p2 - want for an upcoming milestone
User set priority impact status of p2 - want for an upcoming milestone
needs triage
Planning workflow - pending design/dev review.
Check existing issues
Actual Behavior
Given a
calciteDropdownItemSelect
handler that sets focus on another element: After selecting the dropdown item, focus returns to the dropdown's trigger instead of staying on the active element.Listening on the
calciteDropdownSelect
event shows the same behavior.Expected Behavior
Focus stays on the active element.
Reproduction Sample
https://codepen.io/nwhittaker-esri/pen/abegVJm
Reproduction Steps
<input>
, but it instead returns to the trigger buttonReproduction Version
2.13.2
Relevant Info
In terms of how to fix, one thought is to check
document.activeElement
before focusing the trigger. However -- depending on what the dropdown-item does -- if it kicks off a rerender, the element it wants to focus may not exist yet. In the meantime, focusing the trigger may be okay, but if it exists inside a scrolling container, it could cause the container to scroll. So when the new element renders and gains focus, it may be oddly positioned.Another thought is to reorder the dropdown's internal events to complete before the public ones run. I'm not sure if this would solve the problem where the dropdown is inside a scroll container, though.
Alternatively, it might be worth considering whether leveraging the event's
defaultPrevented
flag would be appropriate. If the consumer's handler callspreventDefault()
on theCalciteDropdownItemCustomEvent
event, the dropdown component could take that as an indicator to avoid shifting focus back to the trigger.Regression?
No response
Priority impact
impact - p2 - want for an upcoming milestone
Impact
A workaround exists where the
calciteDropdownItemSelect
handler can read the scroll container'sscrollTop
property, and then add ascroll
handler to the scrolling container that restores the originalscrollTop
value. This isn't ideal as it can cause the scroll container to briefly jump around.To elaborate on the specific use case: I'm writing a component for editing coded value domains. It comprises a list within a modal dialog. I'm using a list for the reordering functionality. Each list-item comprises of a couple inputs and a dropdown action. Some of the dropdown items insert a new list-item relative to current list-item. In that scenarios, I want to move focus to the new list-item's inputs instead of back to the current list-item's trigger.
Depending on the position of the dropdown in the dialog's content area, focusing it can cause the content area to scroll half a page view which can be disorienting.
Calcite package
Esri team
ArcGIS Field Apps
The text was updated successfully, but these errors were encountered: