Skip to content

Instantly share code, notes, and snippets.

@yuschick
Last active November 9, 2017 11:28
Show Gist options
  • Save yuschick/734a9bd93f071a8d757daed15941328d to your computer and use it in GitHub Desktop.
Save yuschick/734a9bd93f071a8d757daed15941328d to your computer and use it in GitHub Desktop.
Accessible Web Apps with React, TypeScript & Ally.js
interface Handle {
disengage(): void;
}
class Dialog extends React.Component<Props> {
dialog: HTMLElement | null;
disabledHandle: Handle;
focusHandle: Handle;
keyHandle: Handle;
componentDidMount() {
this.disabledHandle = Disabled({
filter: this.dialog,
});
this.focusHandle = TabFocus({
context: this.dialog,
});
let element = FirstTab({
context: this.dialog,
defaultToContext: true,
});
element.focus();
this.keyHandle = Key({
escape: () => { this.props.close(); },
});
}
componentWillUnmount() {
this.disabledHandle.disengage();
this.focusHandle.disengage();
this.keyHandle.disengage();
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment