Skip to content

Commit

Permalink
ADA(ADA-1451): Close Video Info modal dialog focus management
Browse files Browse the repository at this point in the history
  • Loading branch information
Tzipi-kaltura committed Nov 12, 2024
1 parent aecdbdd commit 35d39c9
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/utils/popup-keyboard-accessibility.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { h, Component } from 'preact';
import { KeyMap } from './key-map';
import { focusElement } from './focus-element';
import {h, Component} from 'preact';
import {KeyMap} from './key-map';
import {focusElement} from './focus-element';

/**
* wraps a component and handles all key navigation and focus
Expand All @@ -13,6 +13,7 @@ export const withKeyboardA11y = (WrappedComponent): any =>
_accessibleChildren: Array<HTMLElement> = [];
_previouslyActiveElement?: HTMLElement | null;
_isModal: boolean = false;
_morePluginButton: HTMLButtonElement | null;

Check failure on line 16 in src/utils/popup-keyboard-accessibility.tsx

View workflow job for this annotation

GitHub Actions / build-types / running-tests (ubuntu-latest)

Property '_morePluginButton' has no initializer and is not definitely assigned in the constructor.

Check failure on line 16 in src/utils/popup-keyboard-accessibility.tsx

View workflow job for this annotation

GitHub Actions / type-check / running-tests (ubuntu-latest)

Property '_morePluginButton' has no initializer and is not definitely assigned in the constructor.

/**
* after component mounted, focus on relevant element
Expand All @@ -33,6 +34,15 @@ export const withKeyboardA11y = (WrappedComponent): any =>
this._isModal = value;
}

/**
* setter to change to more button state
* @param {boolean} value - the modal state
* @memberOf HOC
*/
set morePluginButton(button: HTMLButtonElement | null) {
this._morePluginButton = button;
}

/**
* handles keydown events
* @param {KeyboardEvent} e - the keyboard event
Expand Down Expand Up @@ -92,6 +102,8 @@ export const withKeyboardA11y = (WrappedComponent): any =>
componentWillUnmount(): void {
if (this._previouslyActiveElement && document.contains(this._previouslyActiveElement)) {
focusElement(this._previouslyActiveElement);
} else if (this._previouslyActiveElement?.classList.contains('playkit-dropdown-item_kw')) {
focusElement(this._morePluginButton);
}
}

Expand All @@ -112,6 +124,7 @@ export const withKeyboardA11y = (WrappedComponent): any =>
clearAccessibleChildren={this.clearAccessibleChildren}
handleKeyDown={this.onKeyDown}
setIsModal={this.setIsModel}
setMoreButton={this.setMoreButton}
/>
);
}
Expand Down Expand Up @@ -172,4 +185,8 @@ export const withKeyboardA11y = (WrappedComponent): any =>
setIsModel = (isModel: boolean): void => {
this.isModal = isModel;
};

setMoreButton = (moreButton: HTMLButtonElement | null): void => {
this.morePluginButton = moreButton;
};
};

0 comments on commit 35d39c9

Please sign in to comment.