@cognitap/radiant 0.0.33 → 0.0.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -2
- package/dist/library/HoverCard.d.ts +26 -0
- package/dist/library/HoverCard.d.ts.map +1 -0
- package/dist/library/HoverCard.js +89 -0
- package/dist/library/HoverCard.js.map +1 -0
- package/dist/library/Popover.d.ts +14 -1
- package/dist/library/Popover.d.ts.map +1 -1
- package/dist/library/Popover.js +11 -6
- package/dist/library/Popover.js.map +1 -1
- package/dist/library/ScrollArea.d.ts +2 -9
- package/dist/library/ScrollArea.d.ts.map +1 -1
- package/dist/library/ScrollArea.js +2 -2
- package/dist/library/ScrollArea.js.map +1 -1
- package/dist/library/ToggleGroup.d.ts +2 -8
- package/dist/library/ToggleGroup.d.ts.map +1 -1
- package/dist/library/ToggleGroup.js +4 -4
- package/dist/library/ToggleGroup.js.map +1 -1
- package/dist/library/Toolbar.d.ts +13 -0
- package/dist/library/Toolbar.d.ts.map +1 -0
- package/dist/library/Toolbar.js +32 -0
- package/dist/library/Toolbar.js.map +1 -0
- package/dist/library/Tooltip.d.ts.map +1 -1
- package/dist/library/Tooltip.js +10 -88
- package/dist/library/Tooltip.js.map +1 -1
- package/dist/library/cn.d.ts.map +1 -1
- package/dist/library/cn.js +4 -0
- package/dist/library/cn.js.map +1 -1
- package/dist/library/index.d.ts +4 -0
- package/dist/library/index.d.ts.map +1 -1
- package/dist/library/index.js +2 -0
- package/dist/library/index.js.map +1 -1
- package/dist/library/internal/accessibleName.d.ts +13 -0
- package/dist/library/internal/accessibleName.d.ts.map +1 -0
- package/dist/library/internal/accessibleName.js +6 -0
- package/dist/library/internal/accessibleName.js.map +1 -0
- package/dist/library/react/useHoverSurface.d.ts +18 -0
- package/dist/library/react/useHoverSurface.d.ts.map +1 -0
- package/dist/library/react/useHoverSurface.js +109 -0
- package/dist/library/react/useHoverSurface.js.map +1 -0
- package/dist/library/react/usePopoverSurface.d.ts +2 -1
- package/dist/library/react/usePopoverSurface.d.ts.map +1 -1
- package/dist/library/react/usePopoverSurface.js +14 -2
- package/dist/library/react/usePopoverSurface.js.map +1 -1
- package/dist/library/react/useRovingFocus.d.ts +3 -2
- package/dist/library/react/useRovingFocus.d.ts.map +1 -1
- package/dist/library/react/useRovingFocus.js +27 -8
- package/dist/library/react/useRovingFocus.js.map +1 -1
- package/dist/library/styles.css +1 -1
- package/dist/library/themes/components.d.ts +9 -0
- package/dist/library/themes/components.d.ts.map +1 -1
- package/dist/library/themes/components.js +2 -0
- package/dist/library/themes/components.js.map +1 -1
- package/docs/architecture.md +6 -4
- package/package.json +1 -1
- package/src/HoverCard.tsx +179 -0
- package/src/Popover.tsx +24 -11
- package/src/ScrollArea.tsx +4 -6
- package/src/ToggleGroup.tsx +5 -8
- package/src/Toolbar.tsx +79 -0
- package/src/Tooltip.tsx +9 -80
- package/src/cn.ts +4 -0
- package/src/index.ts +18 -0
- package/src/internal/accessibleName.ts +12 -0
- package/src/react/useHoverSurface.ts +119 -0
- package/src/react/usePopoverSurface.ts +16 -2
- package/src/react/useRovingFocus.ts +34 -10
- package/src/themes/components.ts +2 -0
package/src/Tooltip.tsx
CHANGED
|
@@ -2,9 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
createContext,
|
|
5
|
-
useCallback,
|
|
6
5
|
useContext,
|
|
7
|
-
useEffect,
|
|
8
6
|
useId,
|
|
9
7
|
useRef,
|
|
10
8
|
useState,
|
|
@@ -20,6 +18,7 @@ import { composeAction } from './internal/events.js'
|
|
|
20
18
|
import type { PopoverSide, PopoverAlign } from './internal/popover.js'
|
|
21
19
|
import { useControllableState } from './react/useControllableState.js'
|
|
22
20
|
import { useComposedRefs } from './react/useComposedRefs.js'
|
|
21
|
+
import { useHoverSurface } from './react/useHoverSurface.js'
|
|
23
22
|
import { usePopoverSurface } from './react/usePopoverSurface.js'
|
|
24
23
|
import { useTransitionHost } from './motion/host.js'
|
|
25
24
|
import type { ThemeStyle } from './themes/defineTheme.js'
|
|
@@ -73,81 +72,14 @@ export function Tooltip({
|
|
|
73
72
|
const contentId = useId()
|
|
74
73
|
const [trigger, setTrigger] = useState<HTMLButtonElement | null>(null)
|
|
75
74
|
const content = useRef<HTMLSpanElement>(null)
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
useEffect(() => {
|
|
84
|
-
latest.current = state.request
|
|
75
|
+
const { enter, leave, dismiss, touch } = useHoverSurface({
|
|
76
|
+
trigger,
|
|
77
|
+
content,
|
|
78
|
+
open: state.value,
|
|
79
|
+
request: state.request,
|
|
80
|
+
openDelay,
|
|
81
|
+
closeDelay
|
|
85
82
|
})
|
|
86
|
-
useEffect(() => () => clear(), [])
|
|
87
|
-
const schedule = useCallback(
|
|
88
|
-
(next: boolean, delay: number) => {
|
|
89
|
-
clear()
|
|
90
|
-
const view = trigger?.ownerDocument.defaultView
|
|
91
|
-
if (!view) return
|
|
92
|
-
timer.current = {
|
|
93
|
-
view,
|
|
94
|
-
id: view.setTimeout(() => {
|
|
95
|
-
timer.current = null
|
|
96
|
-
latest.current(next)
|
|
97
|
-
}, delay)
|
|
98
|
-
}
|
|
99
|
-
},
|
|
100
|
-
[trigger]
|
|
101
|
-
)
|
|
102
|
-
const dismiss = () => {
|
|
103
|
-
clear()
|
|
104
|
-
activity.current.suppressed = true
|
|
105
|
-
state.request(false)
|
|
106
|
-
}
|
|
107
|
-
const enter = (focus = false) => {
|
|
108
|
-
if (focus && !activity.current.focused) activity.current.suppressed = false
|
|
109
|
-
if (focus) activity.current.focused = true
|
|
110
|
-
else activity.current.hovered = true
|
|
111
|
-
clear()
|
|
112
|
-
if (activity.current.suppressed || activity.current.touch) return
|
|
113
|
-
if (focus) state.request(true)
|
|
114
|
-
else if (!state.value) schedule(true, openDelay)
|
|
115
|
-
}
|
|
116
|
-
const leave = (focus = false) => {
|
|
117
|
-
if (focus) {
|
|
118
|
-
activity.current.focused = false
|
|
119
|
-
activity.current.touch = false
|
|
120
|
-
} else activity.current.hovered = false
|
|
121
|
-
if (activity.current.focused || activity.current.hovered) return
|
|
122
|
-
activity.current.suppressed = false
|
|
123
|
-
schedule(false, closeDelay)
|
|
124
|
-
}
|
|
125
|
-
useEffect(() => {
|
|
126
|
-
if (!trigger || !state.value) return
|
|
127
|
-
const move = (event: PointerEvent) => {
|
|
128
|
-
if (
|
|
129
|
-
event.pointerType === 'touch' ||
|
|
130
|
-
activity.current.focused ||
|
|
131
|
-
activity.current.hovered ||
|
|
132
|
-
activity.current.suppressed
|
|
133
|
-
)
|
|
134
|
-
return
|
|
135
|
-
const panel = content.current
|
|
136
|
-
if (!panel) return
|
|
137
|
-
const a = trigger.getBoundingClientRect()
|
|
138
|
-
const b = panel.getBoundingClientRect()
|
|
139
|
-
// Keep a hoverable bridge across the placement gap, including magnified pointer movement.
|
|
140
|
-
const within =
|
|
141
|
-
event.clientX >= Math.min(a.left, b.left) &&
|
|
142
|
-
event.clientX <= Math.max(a.right, b.right) &&
|
|
143
|
-
event.clientY >= Math.min(a.top, b.top) &&
|
|
144
|
-
event.clientY <= Math.max(a.bottom, b.bottom)
|
|
145
|
-
if (within) clear()
|
|
146
|
-
else if (!timer.current) schedule(false, closeDelay)
|
|
147
|
-
}
|
|
148
|
-
trigger.ownerDocument.addEventListener('pointermove', move)
|
|
149
|
-
return () => trigger.ownerDocument.removeEventListener('pointermove', move)
|
|
150
|
-
}, [trigger, state.value, closeDelay, schedule])
|
|
151
83
|
return (
|
|
152
84
|
<TooltipContext.Provider
|
|
153
85
|
value={{
|
|
@@ -160,10 +92,7 @@ export function Tooltip({
|
|
|
160
92
|
enter,
|
|
161
93
|
leave,
|
|
162
94
|
dismiss,
|
|
163
|
-
touch
|
|
164
|
-
activity.current.touch = true
|
|
165
|
-
dismiss()
|
|
166
|
-
}
|
|
95
|
+
touch
|
|
167
96
|
}}
|
|
168
97
|
>
|
|
169
98
|
{children}
|
package/src/cn.ts
CHANGED
|
@@ -63,6 +63,7 @@ export const cn: CnFunction = createCn({
|
|
|
63
63
|
'h-(--rad-slider-length)'
|
|
64
64
|
],
|
|
65
65
|
w: [
|
|
66
|
+
'w-(--rad-hover-card-width)',
|
|
66
67
|
'w-(--rad-scroll-area-size)',
|
|
67
68
|
'w-(--rad-skeleton-width)',
|
|
68
69
|
'w-(--rad-toast-width)',
|
|
@@ -86,6 +87,7 @@ export const cn: CnFunction = createCn({
|
|
|
86
87
|
],
|
|
87
88
|
mb: ['mb-(--rad-fieldset-gap)'],
|
|
88
89
|
gap: [
|
|
90
|
+
'gap-(--rad-toolbar-gap)',
|
|
89
91
|
'gap-(--rad-toggle-group-gap)',
|
|
90
92
|
'gap-(--rad-checkbox-group-gap)',
|
|
91
93
|
'gap-(--rad-fieldset-gap)',
|
|
@@ -113,6 +115,7 @@ export const cn: CnFunction = createCn({
|
|
|
113
115
|
'px-(--rad-tabs-trigger-padding)'
|
|
114
116
|
],
|
|
115
117
|
p: [
|
|
118
|
+
'p-(--rad-toolbar-padding)',
|
|
116
119
|
'p-(--rad-toggle-group-padding)',
|
|
117
120
|
'p-(--rad-toast-padding)',
|
|
118
121
|
'p-(--rad-alert-padding)',
|
|
@@ -126,6 +129,7 @@ export const cn: CnFunction = createCn({
|
|
|
126
129
|
'p-(--rad-tabs-content-padding)'
|
|
127
130
|
],
|
|
128
131
|
rounded: [
|
|
132
|
+
'rounded-(--rad-toolbar-radius)',
|
|
129
133
|
'rounded-(--rad-toggle-group-radius)',
|
|
130
134
|
'rounded-(--rad-toggle-group-indicator-radius)',
|
|
131
135
|
'rounded-(--rad-scroll-area-radius)',
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
export {
|
|
2
|
+
HoverCard,
|
|
3
|
+
HoverCardTrigger,
|
|
4
|
+
HoverCardContent,
|
|
5
|
+
HoverCardPortal,
|
|
6
|
+
useHoverCard
|
|
7
|
+
} from './HoverCard.js'
|
|
8
|
+
export type {
|
|
9
|
+
HoverCardProps,
|
|
10
|
+
HoverCardState,
|
|
11
|
+
HoverCardTriggerProps,
|
|
12
|
+
HoverCardContentProps,
|
|
13
|
+
HoverCardPortalProps,
|
|
14
|
+
HoverCardRenderProps
|
|
15
|
+
} from './HoverCard.js'
|
|
1
16
|
export {
|
|
2
17
|
Combobox,
|
|
3
18
|
ComboboxInput,
|
|
@@ -394,3 +409,6 @@ export type {
|
|
|
394
409
|
ToggleGroupOrientation,
|
|
395
410
|
ToggleGroupAppearance
|
|
396
411
|
} from './ToggleGroup.js'
|
|
412
|
+
|
|
413
|
+
export { Toolbar } from './Toolbar.js'
|
|
414
|
+
export type { ToolbarProps, ToolbarOrientation } from './Toolbar.js'
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type AccessibleName =
|
|
2
|
+
| { 'aria-label': string; 'aria-labelledby'?: string }
|
|
3
|
+
| { 'aria-label'?: string; 'aria-labelledby': string }
|
|
4
|
+
|
|
5
|
+
/** Named composite hosts have the same explicit ownership in every family. */
|
|
6
|
+
export function requireAccessibleName(
|
|
7
|
+
family: string,
|
|
8
|
+
attributes: { 'aria-label'?: string; 'aria-labelledby'?: string }
|
|
9
|
+
) {
|
|
10
|
+
if (!attributes['aria-label']?.trim() && !attributes['aria-labelledby']?.trim())
|
|
11
|
+
throw new TypeError(`${family} requires aria-label or aria-labelledby.`)
|
|
12
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useCallback, useEffect, useRef, type RefObject } from 'react'
|
|
4
|
+
|
|
5
|
+
/** Shared hover/focus timing, dismissal suppression and a bridge across the placement gap. */
|
|
6
|
+
export function useHoverSurface({
|
|
7
|
+
trigger,
|
|
8
|
+
content,
|
|
9
|
+
open,
|
|
10
|
+
request,
|
|
11
|
+
openDelay,
|
|
12
|
+
focusDelay = 0,
|
|
13
|
+
closeDelay
|
|
14
|
+
}: {
|
|
15
|
+
trigger: HTMLElement | null
|
|
16
|
+
content: RefObject<HTMLElement | null>
|
|
17
|
+
open: boolean
|
|
18
|
+
request: (open: boolean) => void
|
|
19
|
+
openDelay: number
|
|
20
|
+
focusDelay?: number
|
|
21
|
+
closeDelay: number
|
|
22
|
+
}) {
|
|
23
|
+
const timer = useRef<{ view: Window; id: number } | null>(null)
|
|
24
|
+
const activity = useRef({ focused: false, hovered: false, suppressed: false, touch: false })
|
|
25
|
+
const latest = useRef(request)
|
|
26
|
+
const clear = () => {
|
|
27
|
+
if (timer.current) timer.current.view.clearTimeout(timer.current.id)
|
|
28
|
+
timer.current = null
|
|
29
|
+
}
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
latest.current = request
|
|
32
|
+
})
|
|
33
|
+
useEffect(() => () => clear(), [])
|
|
34
|
+
const previousOpen = useRef(open)
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
if (!open) {
|
|
37
|
+
clear()
|
|
38
|
+
if (previousOpen.current)
|
|
39
|
+
activity.current.suppressed = activity.current.focused || activity.current.hovered
|
|
40
|
+
}
|
|
41
|
+
previousOpen.current = open
|
|
42
|
+
}, [open])
|
|
43
|
+
const schedule = useCallback(
|
|
44
|
+
(next: boolean, delay: number) => {
|
|
45
|
+
clear()
|
|
46
|
+
const view = trigger?.ownerDocument.defaultView
|
|
47
|
+
if (!view) return
|
|
48
|
+
timer.current = {
|
|
49
|
+
view,
|
|
50
|
+
id: view.setTimeout(() => {
|
|
51
|
+
timer.current = null
|
|
52
|
+
latest.current(next)
|
|
53
|
+
}, delay)
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
[trigger]
|
|
57
|
+
)
|
|
58
|
+
const setOpen = (next: boolean) => {
|
|
59
|
+
clear()
|
|
60
|
+
activity.current.suppressed = !next
|
|
61
|
+
request(next)
|
|
62
|
+
}
|
|
63
|
+
const dismiss = () => setOpen(false)
|
|
64
|
+
const enter = (focus = false) => {
|
|
65
|
+
const wasFocused = activity.current.focused
|
|
66
|
+
if (focus && !wasFocused) activity.current.suppressed = false
|
|
67
|
+
if (focus) activity.current.focused = true
|
|
68
|
+
else activity.current.hovered = true
|
|
69
|
+
clear()
|
|
70
|
+
if (activity.current.suppressed || activity.current.touch || open || (focus && wasFocused))
|
|
71
|
+
return
|
|
72
|
+
if (focus && focusDelay === 0) request(true)
|
|
73
|
+
else schedule(true, focus ? focusDelay : openDelay)
|
|
74
|
+
}
|
|
75
|
+
const leave = (focus = false) => {
|
|
76
|
+
if (focus) {
|
|
77
|
+
activity.current.focused = false
|
|
78
|
+
activity.current.touch = false
|
|
79
|
+
} else activity.current.hovered = false
|
|
80
|
+
if (activity.current.focused || activity.current.hovered) return
|
|
81
|
+
activity.current.suppressed = false
|
|
82
|
+
schedule(false, closeDelay)
|
|
83
|
+
}
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
if (!trigger || !open) return
|
|
86
|
+
const move = (event: PointerEvent) => {
|
|
87
|
+
if (
|
|
88
|
+
event.pointerType === 'touch' ||
|
|
89
|
+
activity.current.focused ||
|
|
90
|
+
activity.current.hovered ||
|
|
91
|
+
activity.current.suppressed
|
|
92
|
+
)
|
|
93
|
+
return
|
|
94
|
+
const panel = content.current
|
|
95
|
+
if (!panel) return
|
|
96
|
+
const a = trigger.getBoundingClientRect(),
|
|
97
|
+
b = panel.getBoundingClientRect()
|
|
98
|
+
const within =
|
|
99
|
+
event.clientX >= Math.min(a.left, b.left) &&
|
|
100
|
+
event.clientX <= Math.max(a.right, b.right) &&
|
|
101
|
+
event.clientY >= Math.min(a.top, b.top) &&
|
|
102
|
+
event.clientY <= Math.max(a.bottom, b.bottom)
|
|
103
|
+
if (within) clear()
|
|
104
|
+
else if (!timer.current) schedule(false, closeDelay)
|
|
105
|
+
}
|
|
106
|
+
trigger.ownerDocument.addEventListener('pointermove', move)
|
|
107
|
+
return () => trigger.ownerDocument.removeEventListener('pointermove', move)
|
|
108
|
+
}, [trigger, content, open, closeDelay, schedule])
|
|
109
|
+
return {
|
|
110
|
+
setOpen,
|
|
111
|
+
enter,
|
|
112
|
+
leave,
|
|
113
|
+
dismiss,
|
|
114
|
+
touch: () => {
|
|
115
|
+
activity.current.touch = true
|
|
116
|
+
dismiss()
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -8,12 +8,13 @@ const layers = new WeakMap<Document, HTMLElement[]>()
|
|
|
8
8
|
|
|
9
9
|
export function usePopoverSurface<Node extends HTMLElement>(
|
|
10
10
|
nodeRef: RefObject<Node | null>,
|
|
11
|
-
trigger:
|
|
11
|
+
trigger: HTMLElement | null,
|
|
12
12
|
open: boolean,
|
|
13
13
|
close: (restore: boolean) => void,
|
|
14
14
|
restoreFocus: RefObject<boolean>,
|
|
15
15
|
options: {
|
|
16
16
|
initialFocusRef?: RefObject<HTMLElement | null>
|
|
17
|
+
onFocusOutside?: () => void
|
|
17
18
|
side: PopoverSide
|
|
18
19
|
align: PopoverAlign
|
|
19
20
|
sideOffset: number
|
|
@@ -136,7 +137,11 @@ export function usePopoverSurface<Node extends HTMLElement>(
|
|
|
136
137
|
return
|
|
137
138
|
if (event.type === 'focusin' && pointerDismissed) return
|
|
138
139
|
if (event.type === 'pointerdown') pointerDismissed = !inside(event.target)
|
|
139
|
-
if (!inside(event.target))
|
|
140
|
+
if (!inside(event.target)) {
|
|
141
|
+
if (event.type === 'focusin' && latest.current.onFocusOutside)
|
|
142
|
+
latest.current.onFocusOutside()
|
|
143
|
+
else latest.current.close(false)
|
|
144
|
+
}
|
|
140
145
|
}
|
|
141
146
|
const escape = (event: KeyboardEvent) => {
|
|
142
147
|
if (
|
|
@@ -171,6 +176,15 @@ export function usePopoverSurface<Node extends HTMLElement>(
|
|
|
171
176
|
observer.observe(trigger)
|
|
172
177
|
observer.observe(node)
|
|
173
178
|
mutations.observe(node, { childList: true, subtree: true, characterData: true })
|
|
179
|
+
// Inline anchors do not report text-size changes through ResizeObserver.
|
|
180
|
+
mutations.observe(trigger, {
|
|
181
|
+
childList: true,
|
|
182
|
+
subtree: true,
|
|
183
|
+
characterData: true,
|
|
184
|
+
attributes: true,
|
|
185
|
+
attributeFilter: ['class', 'style', 'dir']
|
|
186
|
+
})
|
|
187
|
+
|
|
174
188
|
node.addEventListener('toggle', toggle)
|
|
175
189
|
doc.addEventListener('pointerdown', outside, true)
|
|
176
190
|
doc.addEventListener('pointerup', pointerEnd, true)
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
} from 'react'
|
|
10
10
|
|
|
11
11
|
/** A surrounding composite may own all of its nested groups' tab stops. */
|
|
12
|
-
export const CompositeFocusContext = createContext(
|
|
12
|
+
export const CompositeFocusContext = createContext<string | null>(null)
|
|
13
13
|
|
|
14
14
|
type Options<Node extends HTMLElement> = {
|
|
15
15
|
host: RefObject<Node | null>
|
|
@@ -19,6 +19,7 @@ type Options<Node extends HTMLElement> = {
|
|
|
19
19
|
orientation: 'horizontal' | 'vertical'
|
|
20
20
|
loop: boolean
|
|
21
21
|
active?: boolean
|
|
22
|
+
deferTo?: string
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
/** Native hosts and DOM order stay authoritative, including dynamic disabled items. */
|
|
@@ -29,12 +30,21 @@ export function useRovingFocus<Node extends HTMLElement>({
|
|
|
29
30
|
preferred,
|
|
30
31
|
orientation,
|
|
31
32
|
loop,
|
|
32
|
-
active = true
|
|
33
|
+
active = true,
|
|
34
|
+
deferTo
|
|
33
35
|
}: Options<Node>) {
|
|
36
|
+
const ownsFocus = (node: Node) => {
|
|
37
|
+
if (!active) return false
|
|
38
|
+
const parent = deferTo ? node.parentElement?.closest(deferTo) : null
|
|
39
|
+
const surface = node.closest('[popover], dialog')
|
|
40
|
+
// React context crosses portals; native focus ownership stops at a new surface.
|
|
41
|
+
return !parent || !!(surface && parent.contains(surface))
|
|
42
|
+
}
|
|
34
43
|
const items = (node: Node) =>
|
|
35
|
-
Array.from(node.querySelectorAll<
|
|
36
|
-
|
|
37
|
-
|
|
44
|
+
Array.from(node.querySelectorAll<HTMLElement>(selector)).filter(item => {
|
|
45
|
+
const surface = item.closest('[popover], dialog')
|
|
46
|
+
return item.closest(scope) === node && (!surface || !node.contains(surface))
|
|
47
|
+
})
|
|
38
48
|
const enabled = (node: Node) => {
|
|
39
49
|
const view = node.ownerDocument.defaultView!
|
|
40
50
|
return items(node).filter(
|
|
@@ -49,8 +59,16 @@ export function useRovingFocus<Node extends HTMLElement>({
|
|
|
49
59
|
const sync = (node: Node, preferFocus = true) => {
|
|
50
60
|
const all = items(node),
|
|
51
61
|
available = enabled(node)
|
|
62
|
+
const focused = node.ownerDocument.activeElement
|
|
63
|
+
const surface = focused?.closest('[popover], dialog')
|
|
64
|
+
const nestedEntry =
|
|
65
|
+
preferFocus &&
|
|
66
|
+
surface &&
|
|
67
|
+
node.contains(surface) &&
|
|
68
|
+
available.find(item => item.tabIndex === 0)
|
|
52
69
|
const entry =
|
|
53
|
-
(preferFocus && available.find(item => item ===
|
|
70
|
+
(preferFocus && available.find(item => item === focused)) ||
|
|
71
|
+
nestedEntry ||
|
|
54
72
|
available.find(item => item.dataset.value === preferred) ||
|
|
55
73
|
available[0]
|
|
56
74
|
for (const item of all) {
|
|
@@ -60,7 +78,7 @@ export function useRovingFocus<Node extends HTMLElement>({
|
|
|
60
78
|
}
|
|
61
79
|
useLayoutEffect(() => {
|
|
62
80
|
const node = host.current
|
|
63
|
-
if (!node || !
|
|
81
|
+
if (!node || !ownsFocus(node)) return
|
|
64
82
|
const view = node.ownerDocument.defaultView!
|
|
65
83
|
const reconcile = () => sync(node)
|
|
66
84
|
reconcile()
|
|
@@ -106,15 +124,21 @@ export function useRovingFocus<Node extends HTMLElement>({
|
|
|
106
124
|
})
|
|
107
125
|
return {
|
|
108
126
|
onFocus(event: FocusEvent<Node>) {
|
|
109
|
-
if (
|
|
127
|
+
if (
|
|
128
|
+
ownsFocus(event.currentTarget) &&
|
|
129
|
+
enabled(event.currentTarget).some(
|
|
130
|
+
item => item === event.currentTarget.ownerDocument.activeElement
|
|
131
|
+
)
|
|
132
|
+
)
|
|
133
|
+
sync(event.currentTarget)
|
|
110
134
|
},
|
|
111
135
|
onBlur(event: FocusEvent<Node>) {
|
|
112
|
-
if (
|
|
136
|
+
if (ownsFocus(event.currentTarget) && !event.currentTarget.contains(event.relatedTarget))
|
|
113
137
|
sync(event.currentTarget, false)
|
|
114
138
|
},
|
|
115
139
|
onKeyDown(event: KeyboardEvent<Node>) {
|
|
116
140
|
if (
|
|
117
|
-
!
|
|
141
|
+
!ownsFocus(event.currentTarget) ||
|
|
118
142
|
event.defaultPrevented ||
|
|
119
143
|
event.altKey ||
|
|
120
144
|
event.ctrlKey ||
|
package/src/themes/components.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { kebabCase } from './tokens.js'
|
|
|
2
2
|
|
|
3
3
|
/** Explicit component slots; omitted slots reset to CSS fallback semantics. */
|
|
4
4
|
export const componentRegistry = {
|
|
5
|
+
hoverCard: { width: 'css' },
|
|
5
6
|
button: {
|
|
6
7
|
radius: 'css',
|
|
7
8
|
radiusPressed: 'css',
|
|
@@ -500,6 +501,7 @@ export const componentRegistry = {
|
|
|
500
501
|
},
|
|
501
502
|
fieldset: { gap: 'css' },
|
|
502
503
|
checkboxGroup: { gap: 'css' },
|
|
504
|
+
toolbar: { gap: 'css', padding: 'css', radius: 'css', background: 'css' },
|
|
503
505
|
toggleGroup: {
|
|
504
506
|
gap: 'css',
|
|
505
507
|
padding: 'css',
|