calcite-design-system icon indicating copy to clipboard operation
calcite-design-system copied to clipboard

Unable to auto-focus close button when opening modal

Open nwhittaker opened this issue 2 years ago • 1 comments

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

  1. Visit the sample
  2. 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

nwhittaker avatar Jun 21 '22 17:06 nwhittaker

Addressing #4764 first to determine if the fix will apply to this 🐛 as well.

geospatialem avatar Jul 22 '22 18:07 geospatialem

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.

jcfranco avatar Mar 02 '23 01:03 jcfranco

Great catch, Franco!

Also verified in 1.0.7 in the repro sample when changing out the modals active prop to open. Closing this issue out.

geospatialem avatar Mar 02 '23 15:03 geospatialem