Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] feat(Drawer): add shouldReturnFocusOnClose prop #4620

Merged
merged 2 commits into from
Apr 7, 2021
Merged
Changes from all 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
11 changes: 10 additions & 1 deletion packages/core/src/components/drawer/drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ export interface IDrawerProps extends IOverlayableProps, IBackdropProps, IProps
*/
position?: Position;

/**
* Whether the application should return focus to the last active element in the
* document after this drawer closes.
*
* @default true
*/
shouldReturnFocusOnClose?: boolean;

/**
* CSS size of the drawer. This sets `width` if `vertical={false}` (default)
* and `height` otherwise.
Expand Down Expand Up @@ -106,6 +114,7 @@ export class Drawer extends AbstractPureComponent2<IDrawerProps> {
public static defaultProps: IDrawerProps = {
canOutsideClickClose: true,
isOpen: false,
shouldReturnFocusOnClose: true,
style: {},
vertical: false,
};
Expand Down Expand Up @@ -212,7 +221,7 @@ export class Drawer extends AbstractPureComponent2<IDrawerProps> {
};

private handleClosed = (node: HTMLElement) => {
if (this.lastActiveElementBeforeOpened instanceof HTMLElement) {
if (this.props.shouldReturnFocusOnClose && this.lastActiveElementBeforeOpened instanceof HTMLElement) {
this.lastActiveElementBeforeOpened.focus();
}
this.props.onClosed?.(node);
Expand Down