Skip to content

Commit

Permalink
fix(FEC-12918): handle focus change (#310)
Browse files Browse the repository at this point in the history
  • Loading branch information
semarche-kaltura authored Feb 20, 2023
1 parent 604d603 commit cf6105e
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"webpack-dev-server": "^4.9.0"
},
"dependencies": {
"@playkit-js/common": "^1.0.16",
"@playkit-js/common": "^1.1.0",
"@playkit-js/playkit-js-ui": "^0.73.0",
"@playkit-js/ui-managers": "^1.3.2",
"classnames": "^2.2.6"
Expand Down
14 changes: 11 additions & 3 deletions src/components/kitchen-sink/kitchenSink.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Component, h} from 'preact';
import {A11yWrapper} from '@playkit-js/common';
import {A11yWrapper, OnClick} from '@playkit-js/common';
import * as styles from './kitchenSink.scss';
import {QnaMessage, QnaMessageType} from '../../qnaMessageFactory';
import {Thread} from '../thread';
Expand All @@ -14,8 +14,10 @@ import {WhoopseErrorIcon} from '../icons/whoopse-error';
import {NoAnnouncementsYetImage} from '../icons/no-announcements';
import {NoQuestionsYetImage} from '../icons/no-questions';

const {KeyMap} = KalturaPlayer.ui.utils;

export interface KitchenSinkProps {
onClose: () => void;
onClose: OnClick;
threads: QnaMessage[];
dateFormat: string;
hasError: boolean;
Expand Down Expand Up @@ -157,12 +159,18 @@ export class KitchenSink extends Component<KitchenSinkProps, KitchenSinkState> {
}
}

private _handleClose = (event: KeyboardEvent) => {
if (event.keyCode === KeyMap.ESC) {
this.props.onClose(event, true);
}
};

render(props: KitchenSinkProps, state: any) {
const {onClose} = props;
let renderedContent = this._generateContent(props);

return (
<div className={styles.root} aria-live="polite">
<div className={styles.root} aria-live="polite" onKeyUp={this._handleClose}>
{/* header */}
<div className={styles.headerContainer}>
<div className={styles.header}>
Expand Down
10 changes: 8 additions & 2 deletions src/components/plugin-button/pluginButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,19 @@ interface QnaPluginButtonProps {
onClick: OnClick;
showIndication?: boolean;
label?: string;
setRef: (ref: HTMLButtonElement | null) => void;
}

export const QnaPluginButton = withText(translates)(({isActive, onClick, showIndication, ...otherProps}: QnaPluginButtonProps) => {
export const QnaPluginButton = withText(translates)(({isActive, onClick, showIndication, setRef, ...otherProps}: QnaPluginButtonProps) => {
return (
<Tooltip label={otherProps.label} type="bottom">
<A11yWrapper onClick={onClick}>
<button aria-label={otherProps.label} className={[ui.style.upperBarIcon, styles.qnaPluginButton, isActive ? styles.active : ''].join(' ')}>
<button
aria-label={otherProps.label}
className={[ui.style.upperBarIcon, styles.qnaPluginButton, isActive ? styles.active : ''].join(' ')}
ref={node => {
setRef(node);
}}>
<Icon
id="qna-plugin-button"
height={icons.BigSize}
Expand Down
22 changes: 20 additions & 2 deletions src/qna-plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export class QnaPlugin extends KalturaPlayer.core.BasePlugin {
private _pluginState: PluginStates | null = null;
private _contribServices: ContribServices;
private _triggeredByKeyboard = false;
private _pluginButtonRef: HTMLButtonElement | null = null;

static defaultConfig: QnaPluginConfig = {
toastDuration: DefaultToastDuration,
Expand Down Expand Up @@ -170,6 +171,7 @@ export class QnaPlugin extends KalturaPlayer.core.BasePlugin {
this.upperBarManager!.remove(this._pluginIcon);
this._pluginPanel = -1;
this._pluginIcon = -1;
this._pluginButtonRef = null;
}
};

Expand All @@ -187,7 +189,7 @@ export class QnaPlugin extends KalturaPlayer.core.BasePlugin {
const theme = this._getTheme();
return (
<KitchenSink
onClose={this._deactivatePlugin}
onClose={this._handleClose}
dateFormat={this.config.dateFormat}
threads={this._threads}
hasError={this._hasError}
Expand All @@ -214,7 +216,12 @@ export class QnaPlugin extends KalturaPlayer.core.BasePlugin {
onClick: this._handleClickOnPluginIcon as () => void,
component: () => {
return (
<QnaPluginButton showIndication={this._showMenuIconIndication} isActive={this._isPluginActive()} onClick={this._handleClickOnPluginIcon} />
<QnaPluginButton
showIndication={this._showMenuIconIndication}
isActive={this._isPluginActive()}
onClick={this._handleClickOnPluginIcon}
setRef={this._setPluginButtonRef}
/>
);
}
}) as number;
Expand Down Expand Up @@ -257,6 +264,17 @@ export class QnaPlugin extends KalturaPlayer.core.BasePlugin {
}
};

private _setPluginButtonRef = (ref: HTMLButtonElement) => {
this._pluginButtonRef = ref;
};

private _handleClose = (e: OnClickEvent, byKeyboard: boolean) => {
if (byKeyboard) {
this._pluginButtonRef?.focus();
}
this._deactivatePlugin();
};

reset(): void {
this._triggeredByKeyboard = false;
this._hasError = false;
Expand Down
19 changes: 15 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -628,11 +628,12 @@
"@nodelib/fs.scandir" "2.1.5"
fastq "^1.6.0"

"@playkit-js/common@^1.0.16":
version "1.0.16"
resolved "https://registry.yarnpkg.com/@playkit-js/common/-/common-1.0.16.tgz#cee57df0909bcbc1ab85e97b222ce93d05c1104a"
integrity sha512-40QWemEF8QQd23kpFsU20WycVt9A8oRN1wQPq66ORaKMtgXANkTk6V83UNlifa9eNw6K9ovugRnHd9mxCE6Y2w==
"@playkit-js/common@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@playkit-js/common/-/common-1.1.0.tgz#2baa34c16317e8355326537c8d0348e953f555de"
integrity sha512-cMNZy9bmBFaICpUKyJrd8diYEcTdk2Lgm2PgkC8rnyZYnn3p5nIXgCjauVrcOxeRkxNErf8und6Gv3hNsPTi/g==
dependencies:
"@playkit-js/playkit-js-ui" "^0.74.0"
linkify-it "^4.0.1"

"@playkit-js/[email protected]":
Expand Down Expand Up @@ -665,6 +666,16 @@
react-redux "^7.2.0"
redux "^4.0.5"

"@playkit-js/playkit-js-ui@^0.74.0":
version "0.74.0"
resolved "https://registry.yarnpkg.com/@playkit-js/playkit-js-ui/-/playkit-js-ui-0.74.0.tgz#22d0b0f8443cb77352f3ba877b3efc2188bde4ae"
integrity sha512-my/6/HIGGRmP3vJC3vBs0jYwJA2bKyIQlAxH/ZAZccW+xW7iztVskxvkCoAdyFKn1rlddNaq9V962oYKxKtc3Q==
dependencies:
preact "^10.3.4"
preact-i18n "^2.0.0-preactx.2"
react-redux "^7.2.0"
redux "^4.0.5"

"@playkit-js/playkit-js@^0.80.3":
version "0.80.3"
resolved "https://registry.yarnpkg.com/@playkit-js/playkit-js/-/playkit-js-0.80.3.tgz#07e47e560aeadc6ca3b20afde87dfdf4ab8f7ac0"
Expand Down

0 comments on commit cf6105e

Please sign in to comment.