@sanity/ui 2.8.21 → 2.8.23
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/dist/index.esm.js +318 -471
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +318 -471
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +318 -471
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
- package/src/core/components/autocomplete/autocomplete.tsx +31 -42
- package/src/core/hooks/useElementRect/__workshop__/example.tsx +2 -2
- package/src/core/theme/__workshop__/debug/story.tsx +8 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/ui",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.23",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"sanity",
|
|
6
6
|
"ui",
|
|
@@ -110,7 +110,7 @@
|
|
|
110
110
|
"@sanity/icons": "^3.4.0",
|
|
111
111
|
"csstype": "^3.1.3",
|
|
112
112
|
"framer-motion": "11.0.8",
|
|
113
|
-
"react-compiler-runtime": "19.0.0-beta-
|
|
113
|
+
"react-compiler-runtime": "19.0.0-beta-a7bf2bd-20241110",
|
|
114
114
|
"react-refractor": "^2.2.0",
|
|
115
115
|
"use-effect-event": "^1.0.2"
|
|
116
116
|
},
|
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
"@commitlint/config-conventional": "^19.2.2",
|
|
124
124
|
"@juggle/resize-observer": "^3.4.0",
|
|
125
125
|
"@sanity/pkg-utils": "^6.11.9",
|
|
126
|
-
"@sanity/prettier-config": "^1.0.
|
|
126
|
+
"@sanity/prettier-config": "^1.0.3",
|
|
127
127
|
"@sanity/semantic-release-preset": "^5.0.0",
|
|
128
128
|
"@sanity/ui-workshop": "^2.0.16",
|
|
129
129
|
"@storybook/addon-a11y": "^8.4.2",
|
|
@@ -154,7 +154,7 @@
|
|
|
154
154
|
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
|
155
155
|
"@typescript-eslint/parser": "^7.18.0",
|
|
156
156
|
"@vitejs/plugin-react": "^4.3.3",
|
|
157
|
-
"babel-plugin-react-compiler": "19.0.0-beta-
|
|
157
|
+
"babel-plugin-react-compiler": "19.0.0-beta-a7bf2bd-20241110",
|
|
158
158
|
"commitizen": "^4.3.0",
|
|
159
159
|
"cypress": "^13.13.2",
|
|
160
160
|
"cypress-real-events": "^1.13.0",
|
|
@@ -166,7 +166,7 @@
|
|
|
166
166
|
"eslint-plugin-jsx-a11y": "^6.10.2",
|
|
167
167
|
"eslint-plugin-prettier": "^5.2.1",
|
|
168
168
|
"eslint-plugin-react": "^7.37.2",
|
|
169
|
-
"eslint-plugin-react-compiler": "19.0.0-beta-
|
|
169
|
+
"eslint-plugin-react-compiler": "19.0.0-beta-a7bf2bd-20241110",
|
|
170
170
|
"eslint-plugin-react-hooks": "^5.0.0",
|
|
171
171
|
"eslint-plugin-storybook": "^0.11.0",
|
|
172
172
|
"http-server": "^14.1.1",
|
|
@@ -17,7 +17,6 @@ import {
|
|
|
17
17
|
useMemo,
|
|
18
18
|
useReducer,
|
|
19
19
|
useRef,
|
|
20
|
-
useState,
|
|
21
20
|
} from 'react'
|
|
22
21
|
import {EMPTY_ARRAY, EMPTY_RECORD} from '../../constants'
|
|
23
22
|
import {_hasFocus, _raf, focusFirstDescendant} from '../../helpers'
|
|
@@ -185,22 +184,21 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
185
184
|
typeof filterOptionProp === 'function' ? filterOptionProp : DEFAULT_FILTER_OPTION
|
|
186
185
|
|
|
187
186
|
// Element refs
|
|
188
|
-
const
|
|
189
|
-
const
|
|
190
|
-
const
|
|
187
|
+
const rootElementRef = useRef<HTMLDivElement | null>(null)
|
|
188
|
+
const resultsPopoverElementRef = useRef<HTMLDivElement | null>(null)
|
|
189
|
+
const inputElementRef = useRef<HTMLInputElement | null>(null)
|
|
191
190
|
const listBoxElementRef = useRef<HTMLDivElement | null>(null)
|
|
192
191
|
|
|
193
192
|
// Value refs
|
|
194
193
|
const listFocusedRef = useRef(false)
|
|
195
194
|
const valueRef = useRef(value)
|
|
196
195
|
const valuePropRef = useRef(valueProp)
|
|
197
|
-
const
|
|
196
|
+
const popoverMouseWithinRef = useRef(false)
|
|
198
197
|
|
|
199
198
|
// Forward ref to parent
|
|
200
199
|
useImperativeHandle<HTMLInputElement | null, HTMLInputElement | null>(
|
|
201
200
|
forwardedRef,
|
|
202
|
-
() =>
|
|
203
|
-
[inputElement],
|
|
201
|
+
() => inputElementRef.current,
|
|
204
202
|
)
|
|
205
203
|
|
|
206
204
|
const listBoxId = `${id}-listbox`
|
|
@@ -224,13 +222,13 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
224
222
|
// NOTE: This is a workaround for a bug that may happen in Chrome (clicking the scrollbar
|
|
225
223
|
// closes the results in certain situations):
|
|
226
224
|
// - Do not handle blur if the mouse is within the popover
|
|
227
|
-
if (
|
|
225
|
+
if (popoverMouseWithinRef.current) {
|
|
228
226
|
return
|
|
229
227
|
}
|
|
230
228
|
|
|
231
229
|
const elements: HTMLElement[] = (relatedElements || []).concat(
|
|
232
|
-
|
|
233
|
-
|
|
230
|
+
rootElementRef.current ? [rootElementRef.current] : [],
|
|
231
|
+
resultsPopoverElementRef.current ? [resultsPopoverElementRef.current] : [],
|
|
234
232
|
)
|
|
235
233
|
|
|
236
234
|
let focusInside = false
|
|
@@ -246,20 +244,13 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
246
244
|
|
|
247
245
|
if (focusInside === false) {
|
|
248
246
|
dispatch({type: 'root/blur'})
|
|
249
|
-
|
|
247
|
+
popoverMouseWithinRef.current = false
|
|
250
248
|
if (onQueryChange) onQueryChange(null)
|
|
251
249
|
if (onBlur) onBlur(event)
|
|
252
250
|
}
|
|
253
251
|
}, 0)
|
|
254
252
|
},
|
|
255
|
-
[
|
|
256
|
-
onBlur,
|
|
257
|
-
onQueryChange,
|
|
258
|
-
popoverMouseWithin,
|
|
259
|
-
relatedElements,
|
|
260
|
-
resultsPopoverElement,
|
|
261
|
-
rootElement,
|
|
262
|
-
],
|
|
253
|
+
[onBlur, onQueryChange, relatedElements],
|
|
263
254
|
)
|
|
264
255
|
|
|
265
256
|
const handleRootFocus = useCallback((event: FocusEvent<HTMLDivElement>) => {
|
|
@@ -278,7 +269,7 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
278
269
|
(v: string) => {
|
|
279
270
|
dispatch({type: 'value/change', value: v})
|
|
280
271
|
|
|
281
|
-
|
|
272
|
+
popoverMouseWithinRef.current = false
|
|
282
273
|
|
|
283
274
|
if (onSelect) onSelect(v)
|
|
284
275
|
|
|
@@ -287,9 +278,9 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
287
278
|
if (onChange) onChange(v)
|
|
288
279
|
if (onQueryChange) onQueryChange(null)
|
|
289
280
|
|
|
290
|
-
|
|
281
|
+
inputElementRef.current?.focus()
|
|
291
282
|
},
|
|
292
|
-
[
|
|
283
|
+
[onChange, onSelect, onQueryChange],
|
|
293
284
|
)
|
|
294
285
|
|
|
295
286
|
const handleRootKeyDown = useCallback(
|
|
@@ -333,9 +324,9 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
333
324
|
|
|
334
325
|
if (event.key === 'Escape') {
|
|
335
326
|
dispatch({type: 'root/escape'})
|
|
336
|
-
|
|
327
|
+
popoverMouseWithinRef.current = false
|
|
337
328
|
if (onQueryChange) onQueryChange(null)
|
|
338
|
-
|
|
329
|
+
inputElementRef.current?.focus()
|
|
339
330
|
|
|
340
331
|
return
|
|
341
332
|
}
|
|
@@ -347,12 +338,12 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
347
338
|
(listEl === target || listEl?.contains(target)) &&
|
|
348
339
|
!AUTOCOMPLETE_LISTBOX_IGNORE_KEYS.includes(event.key)
|
|
349
340
|
) {
|
|
350
|
-
|
|
341
|
+
inputElementRef.current?.focus()
|
|
351
342
|
|
|
352
343
|
return
|
|
353
344
|
}
|
|
354
345
|
},
|
|
355
|
-
[activeValue, filteredOptions, filteredOptionsLen,
|
|
346
|
+
[activeValue, filteredOptions, filteredOptionsLen, onQueryChange],
|
|
356
347
|
)
|
|
357
348
|
|
|
358
349
|
const handleInputChange = useCallback(
|
|
@@ -386,11 +377,11 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
386
377
|
)
|
|
387
378
|
|
|
388
379
|
const handlePopoverMouseEnter = useCallback(() => {
|
|
389
|
-
|
|
380
|
+
popoverMouseWithinRef.current = true
|
|
390
381
|
}, [])
|
|
391
382
|
|
|
392
383
|
const handlePopoverMouseLeave = useCallback(() => {
|
|
393
|
-
|
|
384
|
+
popoverMouseWithinRef.current = false
|
|
394
385
|
}, [])
|
|
395
386
|
|
|
396
387
|
const handleClearButtonClick = useCallback(() => {
|
|
@@ -398,8 +389,8 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
398
389
|
valueRef.current = ''
|
|
399
390
|
if (onChange) onChange('')
|
|
400
391
|
if (onQueryChange) onQueryChange(null)
|
|
401
|
-
|
|
402
|
-
}, [
|
|
392
|
+
inputElementRef.current?.focus()
|
|
393
|
+
}, [onChange, onQueryChange])
|
|
403
394
|
|
|
404
395
|
const handleClearButtonFocus = useCallback(() => {
|
|
405
396
|
dispatch({type: 'input/focus'})
|
|
@@ -491,9 +482,9 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
491
482
|
|
|
492
483
|
if (openButtonProps.onClick) openButtonProps.onClick(event)
|
|
493
484
|
|
|
494
|
-
_raf(() =>
|
|
485
|
+
_raf(() => inputElementRef.current?.focus())
|
|
495
486
|
},
|
|
496
|
-
[
|
|
487
|
+
[openButtonProps, dispatchOpen],
|
|
497
488
|
)
|
|
498
489
|
|
|
499
490
|
const openButtonNode = useMemo(
|
|
@@ -563,7 +554,7 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
563
554
|
prefix={prefix}
|
|
564
555
|
radius={radius}
|
|
565
556
|
readOnly={readOnly}
|
|
566
|
-
ref={
|
|
557
|
+
ref={inputElementRef}
|
|
567
558
|
role="combobox"
|
|
568
559
|
spellCheck={false}
|
|
569
560
|
suffix={suffix || openButtonNode}
|
|
@@ -575,10 +566,10 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
575
566
|
(event: KeyboardEvent<HTMLDivElement>) => {
|
|
576
567
|
// If the focus is currently in the list, move focus to the input element
|
|
577
568
|
if (event.key === 'Tab') {
|
|
578
|
-
if (listFocused)
|
|
569
|
+
if (listFocused) inputElementRef.current?.focus()
|
|
579
570
|
}
|
|
580
571
|
},
|
|
581
|
-
[
|
|
572
|
+
[listFocused],
|
|
582
573
|
)
|
|
583
574
|
|
|
584
575
|
const content = useMemo(() => {
|
|
@@ -644,11 +635,11 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
644
635
|
{
|
|
645
636
|
content,
|
|
646
637
|
hidden: !expanded,
|
|
647
|
-
inputElement,
|
|
638
|
+
inputElement: inputElementRef.current,
|
|
648
639
|
onMouseEnter: handlePopoverMouseEnter,
|
|
649
640
|
onMouseLeave: handlePopoverMouseLeave,
|
|
650
641
|
},
|
|
651
|
-
|
|
642
|
+
resultsPopoverElementRef,
|
|
652
643
|
)
|
|
653
644
|
}
|
|
654
645
|
|
|
@@ -670,8 +661,8 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
670
661
|
placement={AUTOCOMPLETE_POPOVER_PLACEMENT}
|
|
671
662
|
portal
|
|
672
663
|
radius={radius}
|
|
673
|
-
ref={
|
|
674
|
-
referenceElement={
|
|
664
|
+
ref={resultsPopoverElementRef}
|
|
665
|
+
referenceElement={inputElementRef.current}
|
|
675
666
|
{...popover}
|
|
676
667
|
/>
|
|
677
668
|
)
|
|
@@ -681,11 +672,9 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
681
672
|
filteredOptionsLen,
|
|
682
673
|
handlePopoverMouseEnter,
|
|
683
674
|
handlePopoverMouseLeave,
|
|
684
|
-
inputElement,
|
|
685
675
|
popover,
|
|
686
676
|
radius,
|
|
687
677
|
renderPopover,
|
|
688
|
-
resultsPopoverElement,
|
|
689
678
|
])
|
|
690
679
|
|
|
691
680
|
return (
|
|
@@ -694,7 +683,7 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
694
683
|
onBlur={handleRootBlur}
|
|
695
684
|
onFocus={handleRootFocus}
|
|
696
685
|
onKeyDown={handleRootKeyDown}
|
|
697
|
-
ref={
|
|
686
|
+
ref={rootElementRef}
|
|
698
687
|
>
|
|
699
688
|
{input}
|
|
700
689
|
{results}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {Box, Card, Code, Container, Stack, Text, useElementRect} from '@sanity/ui'
|
|
2
|
-
import {
|
|
2
|
+
import {useState} from 'react'
|
|
3
3
|
import {Grid} from '../../../primitives'
|
|
4
4
|
|
|
5
5
|
export default function ExampleStory() {
|
|
6
6
|
const [element, setElement] = useState<HTMLElement | null>(null)
|
|
7
7
|
const rect = useElementRect(element)
|
|
8
|
-
const size =
|
|
8
|
+
const size = {width: rect?.width || 0, height: rect?.height || 0}
|
|
9
9
|
|
|
10
10
|
return (
|
|
11
11
|
<Box padding={[3, 4, 5]}>
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
ThemeColorState_v2,
|
|
13
13
|
} from '@sanity/ui/theme'
|
|
14
14
|
import {useBoolean, useSelect} from '@sanity/ui-workshop'
|
|
15
|
-
import {CSSProperties
|
|
15
|
+
import {CSSProperties} from 'react'
|
|
16
16
|
import {Badge, Box, Flex, KBD, Stack, Text} from '../../../primitives'
|
|
17
17
|
import {useRootTheme} from '../../useRootTheme'
|
|
18
18
|
|
|
@@ -50,16 +50,13 @@ export default function DebugStory() {
|
|
|
50
50
|
const button = useBoolean('Button', false, 'Props') || false
|
|
51
51
|
const selectable = useBoolean('Selectable', false, 'Props') || false
|
|
52
52
|
|
|
53
|
-
const features: Features =
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}),
|
|
61
|
-
[base, button, scheme, selectable, tone],
|
|
62
|
-
)
|
|
53
|
+
const features: Features = {
|
|
54
|
+
base,
|
|
55
|
+
button,
|
|
56
|
+
schemes: scheme == 'all' ? ['light', 'dark'] : [scheme],
|
|
57
|
+
selectable,
|
|
58
|
+
tones: tone == 'all' ? ['transparent', 'default'] : [tone],
|
|
59
|
+
}
|
|
63
60
|
|
|
64
61
|
return (
|
|
65
62
|
<Flex>
|