Skip to content

Commit

Permalink
- remove tabIndex on a target blur listener;
Browse files Browse the repository at this point in the history
- add blur function to remove tabindex and listener;
  • Loading branch information
JoaoFerreira-FrontEnd committed Oct 18, 2024
1 parent 572f143 commit 3a72361
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/scripts/OutSystems/OSUI/Utils/Accessibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ namespace OutSystems.OSUI.Utils.Accessibility {
* @param targetId
*/
export function SkipToContent(targetId: string): string {
// Method to remove tabindex from skipToContent at onBlur
function _skipToContentOnBlur(e: FocusEvent): void {
OSFramework.OSUI.Helper.AsyncInvocation(() => {
const target = e.target as HTMLElement;

if (target) {
OSFramework.OSUI.Helper.Dom.Attribute.Remove(target, 'tabindex');
target.removeEventListener(OSFramework.OSUI.GlobalEnum.HTMLEvent.Blur, _skipToContentOnBlur);
}
});
}

const result = OutSystems.OSUI.Utils.CreateApiResponse({
errorCode: ErrorCodes.Utilities.FailSkipToContent,
callback: () => {
Expand All @@ -110,7 +122,7 @@ namespace OutSystems.OSUI.Utils.Accessibility {
if (isFocusable === undefined) {
OSFramework.OSUI.Helper.Dom.Attribute.Set(target, 'tabindex', '0');
target.focus();
OSFramework.OSUI.Helper.Dom.Attribute.Remove(target, 'tabindex');
target.addEventListener(OSFramework.OSUI.GlobalEnum.HTMLEvent.Blur, _skipToContentOnBlur);
} else {
target.focus();
}
Expand Down

0 comments on commit 3a72361

Please sign in to comment.