Skip to content

Commit

Permalink
update autofocus type to on/off
Browse files Browse the repository at this point in the history
  • Loading branch information
linh-transcend committed Dec 6, 2024
1 parent 767a313 commit 06bcc92
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/components/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function Main({
const dialogRef = useRef<HTMLDivElement>(null);
useEffect(() => {
if (!isViewStateClosed(viewState) && dialogRef.current) {
const shouldAutofocus = config.autofocus ?? true;
const shouldAutofocus = !config?.autofocus || config?.autofocus === 'on';
// This setTimeout was necessary for the api triggered states, (DoNotSell|OptOut)Disclosure
setTimeout(() => {
if (dialogRef.current && shouldAutofocus) {
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/useViewState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ export function useViewState({
eventTarget: EventTarget;
/** Element previously focused before our ui modal was opened */
savedActiveElement: HTMLElement | null;
/** Whether to on last focused element on reopen */
autofocus?: boolean;
/** Whether to on last focused element on reopen: on or off */
autofocus?: string;
}): {
/** The current view state */
viewState: ViewState;
Expand Down Expand Up @@ -137,7 +137,7 @@ export function useViewState({
* very difficult to interact with. We create an element with maximum focus priority and
* focus it so that when we delete it the user will be at the start of the focus order
* just like if they had freshly loaded the page. */
const shouldFocus = autofocus ?? true;
const shouldFocus = !autofocus || autofocus === 'on';
if (savedActiveElement !== null && shouldFocus) {
savedActiveElement.focus();
} else {
Expand Down

0 comments on commit 06bcc92

Please sign in to comment.