fix(editor): Plus Escape focus return, sheet width rounding
This commit is contained in:
1 parent
021685f6b3
commit
3a7ffa2f8b
3 files changed
+42
-18
No files matched your search
@@ -110,22 +110,33 @@ function useBackRequest(open: boolean, close: () => void) {
|
||||
}, [open, close])
|
||||
}
|
||||
|
||||
const inMenu = (target: EventTarget | null) =>
|
||||
target instanceof Element && target.closest(MENU_PARTS) !== null
|
||||
|
||||
/**
|
||||
* Keyboard focus that leaves the trigger and the list closes « Plus »: the open overlay
|
||||
* would cover the control the focus reached (WCAG 2.4.11). A focus that goes nowhere in
|
||||
* the page (the browser's own interface) leaves it open.
|
||||
* Tab that moves the focus out of the trigger and the list closes « Plus »: the open
|
||||
* overlay would cover the control the focus reached (WCAG 2.4.11). Only a Tab move counts:
|
||||
* a focus the page places elsewhere (the canvas, a tap that keeps it there) leaves the
|
||||
* menu open, so Escape still closes it and returns the focus to « Plus ». A Tab that
|
||||
* reaches the browser's own interface leaves it open too.
|
||||
*/
|
||||
function useFocusLeave(open: boolean, close: () => void) {
|
||||
function useTabLeave(open: boolean, close: () => void) {
|
||||
useEffect(() => {
|
||||
if (!open) return
|
||||
const onOut = (event: FocusEvent) => {
|
||||
const from = event.target instanceof Element ? event.target : null
|
||||
const to = event.relatedTarget
|
||||
if (!from?.closest(MENU_PARTS) || !(to instanceof Element)) return
|
||||
if (!to.closest(MENU_PARTS)) close()
|
||||
let tabbing = false
|
||||
const onKey = (event: KeyboardEvent) => {
|
||||
tabbing = event.key === 'Tab' && inMenu(event.target)
|
||||
}
|
||||
const onIn = (event: FocusEvent) => {
|
||||
if (tabbing && !inMenu(event.target)) close()
|
||||
tabbing = false
|
||||
}
|
||||
document.addEventListener('keydown', onKey, true)
|
||||
document.addEventListener('focusin', onIn, true)
|
||||
return () => {
|
||||
document.removeEventListener('keydown', onKey, true)
|
||||
document.removeEventListener('focusin', onIn, true)
|
||||
}
|
||||
document.addEventListener('focusout', onOut, true)
|
||||
return () => document.removeEventListener('focusout', onOut, true)
|
||||
}, [open, close])
|
||||
}
|
||||
|
||||
@@ -134,5 +145,5 @@ export function useMoreDismiss(open: boolean, close: () => void) {
|
||||
useMoreEscape(open, close)
|
||||
useOutsidePress(open, close)
|
||||
useBackRequest(open, close)
|
||||
useFocusLeave(open, close)
|
||||
useTabLeave(open, close)
|
||||
}
|
||||
Reference in new issue
Block a user