Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions core/src/components/input/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -868,15 +868,6 @@ export class Input implements ComponentInterface {
*/
ev.preventDefault();
}}
onFocusin={(ev) => {
/**
* Prevent the focusin event from bubbling otherwise it will cause the focusin
* event listener in scroll assist to fire. When this fires, focus will be moved
* back to the input even if the clear button was never tapped. This poses issues
* for screen readers as it means users would be unable to swipe past the clear button.
*/
ev.stopPropagation();
}}
onClick={this.clearTextInput}
>
<ion-icon aria-hidden="true" icon={clearIconData}></ion-icon>
Expand Down
18 changes: 18 additions & 0 deletions core/src/utils/input-shims/hacks/scroll-assist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,24 @@ const setManualFocus = (el: HTMLElement) => {
return;
}

/**
* Optimization for scenarios where the currently focused element is a sibling
* of the target element. In such cases, we avoid setting `SKIP_SCROLL_ASSIST`.
*
* This is crucial for accessibility: input elements can now contain focusable
* siblings (e.g., clear buttons, slotted elements). If we didn't skip setting
* the attribute here, screen readers would be unable to navigate to and interact
* with these sibling elements.
*
* Without this check, we would need to call `ev.stopPropagation()` on the
* 'focusin' event of each focusable sibling to prevent the scroll assist
* listener from incorrectly moving focus back to the input. That approach
* would be less maintainable and more error-prone.
*/
if (document.activeElement?.parentNode === el.parentNode) {
return;
}

el.setAttribute(SKIP_SCROLL_ASSIST, 'true');
el.focus();
};
Expand Down
Loading