@oaiz/app-kit 0.1.4199 → 0.1.4201
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/package.json
CHANGED
|
@@ -105,6 +105,7 @@ const DropdownMenuContent = React.forwardRef<
|
|
|
105
105
|
sideOffset = 4,
|
|
106
106
|
onOpenAutoFocus,
|
|
107
107
|
onPointerDownCapture,
|
|
108
|
+
onPointerUpCapture,
|
|
108
109
|
onClickCapture,
|
|
109
110
|
onKeyDownCapture,
|
|
110
111
|
onEscapeKeyDown,
|
|
@@ -116,6 +117,7 @@ const DropdownMenuContent = React.forwardRef<
|
|
|
116
117
|
) => {
|
|
117
118
|
const pointerCloseFocus = usePointerCloseFocus({
|
|
118
119
|
onPointerDownCapture,
|
|
120
|
+
onPointerUpCapture,
|
|
119
121
|
onClickCapture,
|
|
120
122
|
onKeyDownCapture,
|
|
121
123
|
onEscapeKeyDown,
|
|
@@ -19,6 +19,7 @@ const PopoverContent = React.forwardRef<
|
|
|
19
19
|
align = 'center',
|
|
20
20
|
sideOffset = 4,
|
|
21
21
|
onPointerDownCapture,
|
|
22
|
+
onPointerUpCapture,
|
|
22
23
|
onClickCapture,
|
|
23
24
|
onKeyDownCapture,
|
|
24
25
|
onEscapeKeyDown,
|
|
@@ -30,6 +31,7 @@ const PopoverContent = React.forwardRef<
|
|
|
30
31
|
) => {
|
|
31
32
|
const pointerCloseFocus = usePointerCloseFocus({
|
|
32
33
|
onPointerDownCapture,
|
|
34
|
+
onPointerUpCapture,
|
|
33
35
|
onClickCapture,
|
|
34
36
|
onKeyDownCapture,
|
|
35
37
|
onEscapeKeyDown,
|
|
@@ -8,7 +8,32 @@ import { cspNonce } from '../../lib/csp-nonce';
|
|
|
8
8
|
import { cn, usePointerCloseFocus } from '../../lib/utils';
|
|
9
9
|
import { Text } from './text';
|
|
10
10
|
|
|
11
|
-
const
|
|
11
|
+
const SelectInputContext = React.createContext<{
|
|
12
|
+
pointerInput: boolean;
|
|
13
|
+
setPointerInput: (pointer: boolean) => void;
|
|
14
|
+
} | null>(null);
|
|
15
|
+
|
|
16
|
+
function useSelectInput() {
|
|
17
|
+
const input = React.useContext(SelectInputContext);
|
|
18
|
+
if (!input) throw new Error('Select parts must be rendered inside <Select>');
|
|
19
|
+
return input;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function Select(props: React.ComponentProps<typeof SelectPrimitive.Root>) {
|
|
23
|
+
const [pointerInput, setPointerInput] = React.useState(false);
|
|
24
|
+
const input = React.useMemo(
|
|
25
|
+
() => ({ pointerInput, setPointerInput }),
|
|
26
|
+
[pointerInput],
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<SelectInputContext.Provider value={input}>
|
|
31
|
+
<SelectPrimitive.Root {...props} />
|
|
32
|
+
</SelectInputContext.Provider>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
Select.displayName = 'Select';
|
|
12
37
|
|
|
13
38
|
const SelectGroup = SelectPrimitive.Group;
|
|
14
39
|
|
|
@@ -44,18 +69,35 @@ export interface SelectTriggerProps
|
|
|
44
69
|
const SelectTrigger = React.forwardRef<
|
|
45
70
|
React.ElementRef<typeof SelectPrimitive.Trigger>,
|
|
46
71
|
SelectTriggerProps
|
|
47
|
-
>(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
)
|
|
72
|
+
>(
|
|
73
|
+
(
|
|
74
|
+
{ className, variant, size, children, onPointerDown, onKeyDown, ...props },
|
|
75
|
+
ref,
|
|
76
|
+
) => {
|
|
77
|
+
const input = useSelectInput();
|
|
78
|
+
return (
|
|
79
|
+
<SelectPrimitive.Trigger
|
|
80
|
+
ref={ref}
|
|
81
|
+
className={cn(selectTriggerVariants({ variant, size, className }))}
|
|
82
|
+
{...props}
|
|
83
|
+
onPointerDown={(event) => {
|
|
84
|
+
onPointerDown?.(event);
|
|
85
|
+
if (!event.defaultPrevented && event.button === 0 && !event.ctrlKey)
|
|
86
|
+
input.setPointerInput(true);
|
|
87
|
+
}}
|
|
88
|
+
onKeyDown={(event) => {
|
|
89
|
+
onKeyDown?.(event);
|
|
90
|
+
input.setPointerInput(false);
|
|
91
|
+
}}
|
|
92
|
+
>
|
|
93
|
+
{children}
|
|
94
|
+
<SelectPrimitive.Icon asChild>
|
|
95
|
+
<ChevronDown className="h-4 w-4 opacity-50" />
|
|
96
|
+
</SelectPrimitive.Icon>
|
|
97
|
+
</SelectPrimitive.Trigger>
|
|
98
|
+
);
|
|
99
|
+
},
|
|
100
|
+
);
|
|
59
101
|
SelectTrigger.displayName = SelectPrimitive.Trigger.displayName;
|
|
60
102
|
|
|
61
103
|
const SelectScrollUpButton = React.forwardRef<
|
|
@@ -102,7 +144,9 @@ const SelectContent = React.forwardRef<
|
|
|
102
144
|
className,
|
|
103
145
|
children,
|
|
104
146
|
position = 'popper',
|
|
147
|
+
onPointerMove,
|
|
105
148
|
onPointerDownCapture,
|
|
149
|
+
onPointerUpCapture,
|
|
106
150
|
onClickCapture,
|
|
107
151
|
onKeyDownCapture,
|
|
108
152
|
onEscapeKeyDown,
|
|
@@ -112,13 +156,18 @@ const SelectContent = React.forwardRef<
|
|
|
112
156
|
},
|
|
113
157
|
ref,
|
|
114
158
|
) => {
|
|
159
|
+
const input = useSelectInput();
|
|
115
160
|
const pointerCloseFocus = usePointerCloseFocus({
|
|
116
161
|
onPointerDownCapture,
|
|
162
|
+
onPointerUpCapture,
|
|
117
163
|
onClickCapture,
|
|
118
164
|
onKeyDownCapture,
|
|
119
165
|
onEscapeKeyDown,
|
|
120
166
|
onPointerDownOutside,
|
|
121
|
-
onCloseAutoFocus
|
|
167
|
+
onCloseAutoFocus: (event) => {
|
|
168
|
+
input.setPointerInput(false);
|
|
169
|
+
onCloseAutoFocus?.(event);
|
|
170
|
+
},
|
|
122
171
|
});
|
|
123
172
|
|
|
124
173
|
return (
|
|
@@ -132,8 +181,16 @@ const SelectContent = React.forwardRef<
|
|
|
132
181
|
className,
|
|
133
182
|
)}
|
|
134
183
|
position={position}
|
|
184
|
+
onPointerMove={(event) => {
|
|
185
|
+
input.setPointerInput(true);
|
|
186
|
+
onPointerMove?.(event);
|
|
187
|
+
}}
|
|
135
188
|
{...pointerCloseFocus}
|
|
136
189
|
{...props}
|
|
190
|
+
onKeyDownCapture={(event) => {
|
|
191
|
+
input.setPointerInput(false);
|
|
192
|
+
pointerCloseFocus.onKeyDownCapture(event);
|
|
193
|
+
}}
|
|
137
194
|
>
|
|
138
195
|
<SelectScrollUpButton />
|
|
139
196
|
<SelectPrimitive.Viewport
|
|
@@ -178,29 +235,37 @@ export interface SelectItemProps extends React.ComponentPropsWithoutRef<
|
|
|
178
235
|
const SelectItem = React.forwardRef<
|
|
179
236
|
React.ElementRef<typeof SelectPrimitive.Item>,
|
|
180
237
|
SelectItemProps
|
|
181
|
-
>(({ className, children, selectionIndicator = 'check', ...props }, ref) =>
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
238
|
+
>(({ className, children, selectionIndicator = 'check', ...props }, ref) => {
|
|
239
|
+
const input = useSelectInput();
|
|
240
|
+
return (
|
|
241
|
+
<SelectPrimitive.Item
|
|
242
|
+
ref={ref}
|
|
243
|
+
className={cn(
|
|
244
|
+
'relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 text-sm outline-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50',
|
|
245
|
+
selectionIndicator === 'check'
|
|
246
|
+
? 'pl-section pr-inline focus:bg-accent focus:text-foreground'
|
|
247
|
+
: [
|
|
248
|
+
'px-inset data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground',
|
|
249
|
+
input.pointerInput
|
|
250
|
+
? 'data-[state=unchecked]:hover:bg-accent data-[state=unchecked]:hover:text-foreground forced-colors:hover:outline-solid forced-colors:hover:outline-2 forced-colors:hover:-outline-offset-2 forced-colors:hover:outline-[Highlight]'
|
|
251
|
+
: 'data-[state=unchecked]:focus:bg-accent data-[state=unchecked]:focus:text-foreground forced-colors:focus:outline-solid forced-colors:focus:outline-2 forced-colors:focus:-outline-offset-2 forced-colors:focus:outline-[Highlight] focus:ring-2 focus:ring-inset focus:ring-ring data-[state=checked]:focus:ring-primary-foreground',
|
|
252
|
+
],
|
|
253
|
+
className,
|
|
254
|
+
)}
|
|
255
|
+
{...props}
|
|
256
|
+
>
|
|
257
|
+
{selectionIndicator === 'check' && (
|
|
258
|
+
<span className="absolute left-inline flex h-3.5 w-3.5 items-center justify-center">
|
|
259
|
+
<SelectPrimitive.ItemIndicator>
|
|
260
|
+
<Check className="h-4 w-4" />
|
|
261
|
+
</SelectPrimitive.ItemIndicator>
|
|
262
|
+
</span>
|
|
263
|
+
)}
|
|
200
264
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
)
|
|
265
|
+
<SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
|
|
266
|
+
</SelectPrimitive.Item>
|
|
267
|
+
);
|
|
268
|
+
});
|
|
204
269
|
SelectItem.displayName = SelectPrimitive.Item.displayName;
|
|
205
270
|
|
|
206
271
|
const SelectSeparator = React.forwardRef<
|
|
@@ -8,7 +8,23 @@ const TooltipProvider = TooltipPrimitive.Provider;
|
|
|
8
8
|
|
|
9
9
|
const Tooltip = TooltipPrimitive.Root;
|
|
10
10
|
|
|
11
|
-
const TooltipTrigger =
|
|
11
|
+
const TooltipTrigger = React.forwardRef<
|
|
12
|
+
React.ElementRef<typeof TooltipPrimitive.Trigger>,
|
|
13
|
+
React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Trigger>
|
|
14
|
+
>(({ onFocus, ...props }, ref) => (
|
|
15
|
+
<TooltipPrimitive.Trigger
|
|
16
|
+
{...props}
|
|
17
|
+
ref={ref}
|
|
18
|
+
onFocus={(event) => {
|
|
19
|
+
onFocus?.(event);
|
|
20
|
+
// Radix skips its open handler when the composed handler prevents the event.
|
|
21
|
+
if (event.currentTarget.hasAttribute('data-pointer-close-focus')) {
|
|
22
|
+
event.preventDefault();
|
|
23
|
+
}
|
|
24
|
+
}}
|
|
25
|
+
/>
|
|
26
|
+
));
|
|
27
|
+
TooltipTrigger.displayName = TooltipPrimitive.Trigger.displayName;
|
|
12
28
|
|
|
13
29
|
interface TooltipContentProps extends React.ComponentPropsWithoutRef<
|
|
14
30
|
typeof TooltipPrimitive.Content
|
package/src/lib/utils.ts
CHANGED
|
@@ -13,11 +13,12 @@ export function cn(...inputs: ClassValue[]) {
|
|
|
13
13
|
* and scoped shortcuts; the marker clears on the next keydown or blur.
|
|
14
14
|
*/
|
|
15
15
|
export function suppressPointerAutoFocusRing(): void {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
if (typeof document === 'undefined') return;
|
|
17
|
+
const previousActive = document.activeElement;
|
|
18
|
+
// React dispatches `onFocus` from the root's bubbling `focusin`, so this
|
|
19
|
+
// capture listener on the document marks the element first.
|
|
20
|
+
const markRestoredFocus = (event: FocusEvent) => {
|
|
21
|
+
const active = event.target;
|
|
21
22
|
if (
|
|
22
23
|
!(active instanceof HTMLElement) ||
|
|
23
24
|
active === document.body ||
|
|
@@ -33,15 +34,27 @@ export function suppressPointerAutoFocusRing(): void {
|
|
|
33
34
|
};
|
|
34
35
|
active.addEventListener('blur', clear, { once: true });
|
|
35
36
|
window.addEventListener('keydown', clear, { capture: true, once: true });
|
|
36
|
-
}
|
|
37
|
+
};
|
|
38
|
+
// Radix restores focus synchronously after `onCloseAutoFocus`, so every
|
|
39
|
+
// element focused before the microtask runs is marked; each marker clears on
|
|
40
|
+
// that element's blur.
|
|
41
|
+
document.addEventListener('focusin', markRestoredFocus, true);
|
|
42
|
+
// Outside dismissal can finish without moving focus.
|
|
43
|
+
queueMicrotask(() =>
|
|
44
|
+
document.removeEventListener('focusin', markRestoredFocus, true),
|
|
45
|
+
);
|
|
37
46
|
}
|
|
38
47
|
|
|
48
|
+
const SELECTABLE_ITEM_SELECTOR =
|
|
49
|
+
'[role="option"], [role="menuitem"], [role="menuitemcheckbox"], [role="menuitemradio"]';
|
|
50
|
+
|
|
39
51
|
interface PointerCloseFocusHandlers<
|
|
40
52
|
TEscape extends Event,
|
|
41
53
|
TPointerOutside extends Event,
|
|
42
54
|
TCloseAutoFocus extends Event,
|
|
43
55
|
> {
|
|
44
56
|
onPointerDownCapture?: React.PointerEventHandler | undefined;
|
|
57
|
+
onPointerUpCapture?: React.PointerEventHandler | undefined;
|
|
45
58
|
onClickCapture?: React.MouseEventHandler | undefined;
|
|
46
59
|
onKeyDownCapture?: React.KeyboardEventHandler | undefined;
|
|
47
60
|
onEscapeKeyDown?: ((event: TEscape) => void) | undefined;
|
|
@@ -68,6 +81,7 @@ export function usePointerCloseFocus<
|
|
|
68
81
|
) {
|
|
69
82
|
const {
|
|
70
83
|
onPointerDownCapture,
|
|
84
|
+
onPointerUpCapture,
|
|
71
85
|
onClickCapture,
|
|
72
86
|
onKeyDownCapture,
|
|
73
87
|
onEscapeKeyDown,
|
|
@@ -81,6 +95,16 @@ export function usePointerCloseFocus<
|
|
|
81
95
|
closedByPointerRef.current = true;
|
|
82
96
|
onPointerDownCapture?.(event);
|
|
83
97
|
},
|
|
98
|
+
onPointerUpCapture: (event: React.PointerEvent) => {
|
|
99
|
+
// Releasing a drag over an item selects it without a click.
|
|
100
|
+
if (
|
|
101
|
+
event.target instanceof Element &&
|
|
102
|
+
event.target.closest(SELECTABLE_ITEM_SELECTOR)
|
|
103
|
+
) {
|
|
104
|
+
closedByPointerRef.current = true;
|
|
105
|
+
}
|
|
106
|
+
onPointerUpCapture?.(event);
|
|
107
|
+
},
|
|
84
108
|
onClickCapture: (event: React.MouseEvent) => {
|
|
85
109
|
if (event.detail > 0) closedByPointerRef.current = true;
|
|
86
110
|
onClickCapture?.(event);
|