From 6af612acc1a7a09b319c17283b0f53132c84e0f5 Mon Sep 17 00:00:00 2001 From: Jo du Plessis Date: Wed, 12 Jun 2024 14:37:44 +0200 Subject: [PATCH] refine autoFocus behaviour --- packages/core/src/hooks/focus.hook.ts | 44 ++++++----------------- packages/core/src/input/input-popover.tsx | 23 ++++++++---- packages/core/src/modal/modal.tsx | 3 +- packages/core/src/popover/popover.css | 2 +- packages/core/src/popover/popover.tsx | 3 +- 5 files changed, 31 insertions(+), 44 deletions(-) diff --git a/packages/core/src/hooks/focus.hook.ts b/packages/core/src/hooks/focus.hook.ts index 402ed07a..9a1a6eeb 100644 --- a/packages/core/src/hooks/focus.hook.ts +++ b/packages/core/src/hooks/focus.hook.ts @@ -2,11 +2,18 @@ import { useEffect, useRef } from 'react' import { documentObject, getKey } from '../helpers' import { CoreViewProps } from '../types' -export const FOCUSABLE = - 'a[href]:not([disabled]), button:not([disabled]), textarea:not([disabled]), input:not([disabled]), input[type="text"]:not([disabled]), input[type="radio"]:not([disabled]), input[type="checkbox"]:not([disabled]), select:not([disabled])' +export const FOCUSABLE = [ + 'a[href]:not([disabled])', + 'button:not([disabled])', + 'input:not([disabled])', + 'select:not([disabled])', + 'textarea:not([disabled])', + '[tabindex]:not([tabindex="-1"])', + '[contenteditable]' +] export type FocusTrapProps = { - focusable?: string + focusable?: string[] onEscape?: any } & CoreViewProps @@ -30,40 +37,11 @@ export const useFocus = (focusable = FOCUSABLE, arrowNavigation = false) => { firstFocusableEl.current?.focus() } } - - /* - Needs refactoring after the