siemens / ix

Siemens Industrial Experience is a design system for designers and developers, to consistently create the perfect digital experience for industrial software products.
https://ix.siemens.io/
MIT License
203 stars 69 forks source link

Allow programmatic focus and focus the first focussable nested element in a modal #1531

Open Aiderlei opened 1 week ago

Aiderlei commented 1 week ago

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 the AfterViewInit 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 encapsulated button element. Calling the focus 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 the ix-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:

github-actions[bot] commented 1 week ago

🤖 Hello @Aiderlei

Your issue will be analyzed and is part of our internal workflow. To get informed about our workflow please checkout the Contributing Guidelines

JIRA: IX-1886