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

disable-autofocus-on-first-element #346

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const Popup = forwardRef<PopupActions, PopupProps>(
open = undefined,
disabled = false,
nested = false,
disabledAutofocus = false,
closeOnDocumentClick = true,
repositionOnResize = true,
closeOnEscape = true,
Expand Down Expand Up @@ -79,7 +80,9 @@ export const Popup = forwardRef<PopupActions, PopupProps>(
if (isOpen) {
focusedElBeforeOpen.current = document.activeElement;
setPosition();
focusContentOnOpen(); // for accessibility
if (!disabledAutofocus) {
focusContentOnOpen(); // for accessibility
}
lockScrolll();
} else {
resetScroll();
Expand Down
1 change: 1 addition & 0 deletions src/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface PopupProps {
lockScroll?: boolean;
closeOnDocumentClick?: boolean;
closeOnEscape?: boolean;
disabledAutofocus?: boolean;
repositionOnResize?: boolean;
mouseEnterDelay?: number;
mouseLeaveDelay?: number;
Expand Down
18 changes: 18 additions & 0 deletions stories/Modal.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,21 @@ GlobalModalWithRef.args = {
onOpen: () => alert('popup opened '),
modal: true,
};

const DisabledAutofocusOnFirstElementTemplate: Story<PopupProps> = args => (
<Center>
<Popup
{...args}
trigger={<Button>Open modal</Button>}
>
<input placeholder='Start type'/>
</Popup>
</Center>
);

export const DisabledAutofocusOnFirstElement = DisabledAutofocusOnFirstElementTemplate.bind({});

DisabledAutofocusOnFirstElement.args = {
modal: true,
disabledAutofocus: true
};