Allow programmatic focus and focus the first focussable nested element in a modal #1531
Open
2 tasks done
Labels
triage
We discuss this topic in our internal weekly
Workflow: Issue created
JIRA issue is created and will be analyzed
Prerequisites
What happened?
I encountered an issue when trying to set the initial focus on a button within a confirmation modal using the
ix-modal
component.My approach was to use the focus method from the native browser API in combination with
ViewChild
, within theAfterViewInit
lifecycle hook. However, the focus state did not appear on the button, even though I could manually trigger it via keyboard tabbing.Additionally, I was unable to set the focus state through Chrome DevTools by forcing focus on the DOM node of the
ix-button
or its encapsulatedbutton
element. Calling thefocus
method directly on these nodes also did not result in the expected focus behavior.I suggest that all iX components should support a programmatic way to set focus.
Upon further investigation, I discovered that the native
dialog
HTML element, which theix-modal
component uses internally, automatically focuses the first focusable nested element. This is a built-in accessibility feature in browsers (see MDN for more details).I created a codepen to demonstrate this behavior.
However, this behavior is not present in the
ix-modal
component. I propose adding this default behavior to ensure better accessibility and consistency.What type of frontend framework are you seeing the problem on?
Angular
Which version of iX do you use?
v2.5.0
Code to produce this issue.
I’ve included a StackBlitz example to demonstrate that:
The text was updated successfully, but these errors were encountered: