@sanity/ui 2.4.0 → 2.5.0

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/ui",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "keywords": [
5
5
  "sanity",
6
6
  "ui",
@@ -61,6 +61,8 @@ export interface AutocompleteProps<Option extends BaseAutocompleteOption = BaseA
61
61
  onSelect?: (value: string) => void
62
62
  /** @beta */
63
63
  openButton?: boolean | AutocompleteOpenButtonProps
64
+ /** @beta */
65
+ openOnFocus?: boolean
64
66
  /** The options to render. */
65
67
  options?: Option[]
66
68
  padding?: number | number[]
@@ -138,6 +140,7 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
138
140
  onQueryChange,
139
141
  onSelect,
140
142
  openButton,
143
+ openOnFocus,
141
144
  options: optionsProp,
142
145
  padding: paddingProp = 3,
143
146
  popover = EMPTY_RECORD,
@@ -354,15 +357,23 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
354
357
  [onQueryChange],
355
358
  )
356
359
 
360
+ const dispatchOpen = useCallback(() => {
361
+ dispatch({
362
+ type: 'root/open',
363
+ query: value ? renderValue(value, currentOption) : '',
364
+ })
365
+ }, [currentOption, renderValue, value])
366
+
357
367
  const handleInputFocus = useCallback(
358
368
  (event: FocusEvent<HTMLInputElement>) => {
359
369
  if (!focused) {
360
370
  dispatch({type: 'input/focus'})
361
371
 
362
372
  if (onFocus) onFocus(event)
373
+ if (openOnFocus) dispatchOpen()
363
374
  }
364
375
  },
365
- [focused, onFocus],
376
+ [focused, onFocus, openOnFocus, dispatchOpen],
366
377
  )
367
378
 
368
379
  const handlePopoverMouseEnter = useCallback(() => {
@@ -467,16 +478,13 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
467
478
 
468
479
  const handleOpenClick = useCallback(
469
480
  (event: MouseEvent<HTMLButtonElement>) => {
470
- dispatch({
471
- type: 'root/open',
472
- query: value ? renderValue(value, currentOption) : '',
473
- })
481
+ dispatchOpen()
474
482
 
475
483
  if (openButtonProps.onClick) openButtonProps.onClick(event)
476
484
 
477
485
  _raf(() => inputElementRef.current?.focus())
478
486
  },
479
- [currentOption, openButtonProps, renderValue, value],
487
+ [openButtonProps, dispatchOpen],
480
488
  )
481
489
 
482
490
  const openButtonNode = useMemo(