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

Modal: Support initialFocus option for focusing a specific element when opened. #8073

Closed
2 of 5 tasks
driskull opened this issue Oct 27, 2023 · 5 comments
Closed
2 of 5 tasks
Labels
0 - new New issues that need assignment. ArcGIS Maps SDK for JavaScript Issues logged by ArcGIS SDK for JavaScript team members. calcite-components Issues specific to the @esri/calcite-components package. enhancement Issues tied to a new feature or request. 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.

Comments

@driskull
Copy link
Member

Check existing issues

Description

In rare cases, it may be needed to focus a specific element when a focus trapped component is opened. For example, focusing a username input within a modal rather than the close button by default. This is a convenience to allow users to quickly type in their username/password and should not be done for every scenario.

In order to support this, we should introduce/expose the initialFocus focus-trap option to allow a user to set a specific element or query string to focus when being opened.

Acceptance Criteria

expose initialFocus option as a property on modal

Relevant Info

No response

Which Component

modal

Example Use Case

const modal = document.querySelector("calcite-modal");
modal.initialFocus = document.querySelector("calcite-input");

Priority impact

p2 - want for current milestone

Calcite package

  • @esri/calcite-components
  • @esri/calcite-components-react
  • @esri/calcite-design-tokens
  • @esri/eslint-plugin-calcite-components

Esri team

ArcGIS Maps SDK for JavaScript

@driskull driskull added enhancement Issues tied to a new feature or request. 0 - new New issues that need assignment. needs triage Planning workflow - pending design/dev review. labels Oct 27, 2023
@github-actions github-actions bot added ArcGIS Maps SDK for JavaScript Issues logged by ArcGIS SDK for JavaScript team members. 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 labels Oct 27, 2023
@driskull
Copy link
Member Author

Maybe this isn't necessary as I'm able to workaround this by doing the following:

onCalciteModalOpen={() => {
    requestAnimationFrame(() => {
      this.myEl?.setFocus();
    });
  }}

@macandcheese
Copy link
Contributor

It's come up a few times that a reciprocal functionality could also be useful - a returnFocus option to focus an element of choice on Modal / Sheet close - something different than the invoking element. While the default behavior works most of the time, there have been some cases where devs want focus to be placed elsewhere on close.

As mentioned for initialFocus, there are workarounds, but it might be nice to build in if this request goes forward.

@jcfranco
Copy link
Member

Maybe this isn't necessary as I'm able to workaround this by doing the following:

onCalciteModalOpen={() => {
    requestAnimationFrame(() => {
      this.myEl?.setFocus();
    });
  }}

This might be a bug due to modal using componentOnReady when opened and the different behavior in the components output target described in this PR.


As mentioned for initialFocus, there are workarounds, but it might be nice to build in if this request goes forward.

Slightly related, but we decided to move away from setting initial focus via setFocus a while back for the following reasons:

Ideally, the focus should be on the first focusable element as defined by a11y guidelines and consistent with how delegatesFocus works.

If we have focusId then there could be UX inconsistencies where developers are determining where to focus first. Ideally, this is handled by the component either by focusing the first element or using a focus trap to do so.

Would the proposed initialFocus behavior go against this?

@driskull
Copy link
Member Author

Yeah I agree with your assessment @jcfranco. We shouldn't have to do this.

@geospatialem
Copy link
Member

Closing the above as unplanned based on Franco's comment above.

There is also some similarly-related content available regarding focus order on the Modal component page.

@geospatialem geospatialem closed this as not planned Won't fix, can't repro, duplicate, stale Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0 - new New issues that need assignment. ArcGIS Maps SDK for JavaScript Issues logged by ArcGIS SDK for JavaScript team members. calcite-components Issues specific to the @esri/calcite-components package. enhancement Issues tied to a new feature or request. 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.
Projects
None yet
Development

No branches or pull requests

4 participants