calcite-design-system
calcite-design-system copied to clipboard
Unable to auto-focus close button when opening modal
Actual Behavior
Given a modal with a calciteModalOpen
handler that calls setFocus('close-button')
on itself. Upon opening, the modal's first focusable Calcite element that implements setFocus()
gains focus.
Expected Behavior
Given a modal with a calciteModalOpen
handler that calls setFocus('close-button')
on itself. Upon opening, the modal's close button gains focus.
Reproduction Sample
https://codepen.io/nwhittaker-esri/pen/gOvJyXJ
Reproduction Steps
- Visit the sample
- Click the Open modal button
Reproduction Version
beta.83
Relevant Info
Interestingly, if the modal's first focusable element is not a Calcite element, the expected behavior plays out.
Likely due to the fact that, in the reported scenario, setFocus()
ends up getting called twice where the first invocation yields a promise and the second invocation does not:
https://github.com/Esri/calcite-components/blob/7265339f9b6d55d68fd1b5ab4a658ce9b07ea406/src/utils/dom.ts#L169
Regression?
No response
Addressing #4764 first to determine if the fix will apply to this 🐛 as well.
This is no longer reproducible in the latest release (see https://codepen.io/jcfranco/pen/OJopzbG). Probably addressed by https://github.com/Esri/calcite-components/issues/6139.
Great catch, Franco!
Also verified in 1.0.7
in the repro sample when changing out the modal
s active
prop to open
. Closing this issue out.