@economic/taco 1.14.1 → 1.14.3

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.
@@ -85,9 +85,7 @@ const Single = /*#__PURE__*/React__default.forwardRef(function Select2TriggerSin
85
85
  readOnly,
86
86
  tags
87
87
  } = useSelect2Context();
88
- const contentClassName = cn('truncate', {
89
- 'flex gap-1': tags
90
- });
88
+ const contentClassName = cn('truncate flex items-center gap-1');
91
89
  const currentValue = children.find(matchesValue(value));
92
90
  let output;
93
91
  if (currentValue) {
@@ -101,7 +99,6 @@ const Single = /*#__PURE__*/React__default.forwardRef(function Select2TriggerSin
101
99
  }, currentValue.props.children);
102
100
  } else {
103
101
  output = /*#__PURE__*/React__default.createElement(React__default.Fragment, null, currentValue.props.icon ? typeof currentValue.props.icon === 'string' ? /*#__PURE__*/React__default.createElement(Icon, {
104
- className: "mr-1",
105
102
  name: currentValue.props.icon
106
103
  }) : currentValue.props.icon : null, currentValue.props.children);
107
104
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Trigger.js","sources":["../../../../../../../../src/components/Select2/components/Trigger.tsx"],"sourcesContent":["import React from 'react';\nimport cn from 'classnames';\nimport { Tag } from '../../Tag/Tag';\nimport { Tooltip } from '../../Tooltip/Tooltip';\nimport { Icon } from '../../Icon/Icon';\nimport { Badge } from '../../Badge/Badge';\nimport { getInputClasses } from '../../Input/util';\nimport { Select2OptionValue } from '../types';\nimport { useSelect2Context } from './Context';\nimport { Select2OptionProps } from './Option';\nimport { getIndexOfFirstChildOverflowingParent } from '../../../utils/dom';\nimport { ScrollArea } from '../../ScrollArea/ScrollArea';\n\ntype Select2TriggerProps = Omit<React.HTMLAttributes<HTMLButtonElement>, 'children' | 'defaultValue' | 'onChange' | 'value'> & {\n children: React.ReactElement<Select2OptionProps>[];\n};\n\nexport const Trigger = React.forwardRef<HTMLButtonElement, Select2TriggerProps>(function Select2Trigger(props, ref) {\n const { multiple, value } = useSelect2Context();\n\n if (Array.isArray(value) || multiple) {\n const values = Array.isArray(value) ? value : value !== undefined ? [value] : undefined;\n return <Multiple {...props} ref={ref} values={values} />;\n }\n\n return <Single {...props} ref={ref} value={value} />;\n});\n\ntype ButtonProps = React.HTMLAttributes<HTMLButtonElement> &\n Omit<Select2TriggerProps, 'children' | 'open' | 'setValue' | 'value'>;\n\nconst Button = React.forwardRef<HTMLButtonElement, ButtonProps>(function Select2TriggerButton(props, ref) {\n const { children, onClick, tabIndex = 0, ...otherProps } = props;\n const { disabled, highlighted, invalid, open, readOnly } = useSelect2Context();\n\n const className = cn(\n 'cursor-pointer !px-1.5',\n getInputClasses({ ...props, disabled, highlighted, invalid, readOnly }).replace('w-full ', ''),\n { 'w-full': !props.className?.includes('w-') },\n props.className\n );\n\n const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {\n if (disabled || readOnly) {\n event.preventDefault();\n return;\n }\n\n if (typeof onClick === 'function') {\n onClick(event);\n }\n };\n\n return (\n <button\n {...otherProps}\n aria-invalid={invalid ? true : undefined}\n aria-readonly={readOnly ? true : undefined}\n className={className}\n disabled={disabled}\n onClick={handleClick}\n ref={ref}\n role=\"combobox\"\n tabIndex={disabled || readOnly ? -1 : tabIndex}\n type=\"button\">\n {children}\n <Icon name={open ? 'chevron-up' : 'chevron-down'} className=\"-mr-1 ml-auto\" />\n </button>\n );\n});\n\ntype SingleProps = Omit<Select2TriggerProps, 'value'> & { value?: Select2OptionValue };\n\nconst Single = React.forwardRef<HTMLButtonElement, SingleProps>(function Select2TriggerSingle(props, ref) {\n const { children, value, ...buttonProps } = props;\n const { disabled, readOnly, tags } = useSelect2Context();\n const contentClassName = cn('truncate', {\n 'flex gap-1': tags,\n });\n\n const currentValue = children.find(matchesValue(value));\n\n let output;\n\n if (currentValue) {\n if (tags) {\n output = (\n <Tag\n className=\"truncate\"\n color={currentValue.props.color}\n disabled={disabled}\n icon={currentValue.props.icon}\n readOnly={readOnly}>\n {currentValue.props.children}\n </Tag>\n );\n } else {\n output = (\n <>\n {currentValue.props.icon ? (\n typeof currentValue.props.icon === 'string' ? (\n <Icon className=\"mr-1\" name={currentValue.props.icon} />\n ) : (\n currentValue.props.icon\n )\n ) : null}\n {currentValue.props.children}\n </>\n );\n }\n }\n\n return (\n <Button {...buttonProps} ref={ref}>\n <span className={contentClassName}>{output}</span>\n </Button>\n );\n});\n\ntype MultipleProps = Omit<Select2TriggerProps, 'value'> & {\n values?: Select2OptionValue[];\n};\n\nconst Multiple = React.forwardRef<HTMLButtonElement, MultipleProps>(function Select2TriggerMultiple(props, ref) {\n const { children, values = [], ...buttonProps } = props;\n const { disabled, open, readOnly, setValue, tags } = useSelect2Context();\n const contentRef = React.useRef<HTMLSpanElement>(null);\n\n const createClickHandler = tagValue => event => {\n event?.stopPropagation();\n event?.preventDefault();\n\n if (!disabled && !readOnly) {\n setValue(tagValue);\n }\n };\n const valuesAsChildren = values.map(value =>\n children.find(c => c.props.value === value)\n ) as React.ReactElement<Select2OptionProps>[];\n\n if (open) {\n return (\n <span className=\"relative h-8\">\n <Button {...buttonProps} className={cn('absolute z-20', buttonProps.className)} ref={ref}>\n <ScrollArea className=\"my-1 flex max-h-[5.5rem] flex-col\">\n <span className=\"flex flex-wrap gap-1\">\n {valuesAsChildren.map(child => (\n <Tag\n key={child.props.value}\n className=\"truncate\"\n color={tags ? child.props.color : undefined}\n disabled={disabled}\n icon={child.props.icon}\n onDelete={open ? createClickHandler(child.props.value) : undefined}\n readOnly={readOnly}>\n {child.props.children}\n </Tag>\n ))}\n </span>\n </ScrollArea>\n </Button>\n </span>\n );\n }\n\n const boundaryIndex = contentRef.current ? getIndexOfFirstChildOverflowingParent(contentRef.current, 30) : undefined;\n\n return (\n <Button {...buttonProps} ref={ref}>\n <span className=\"relative flex items-center gap-1 overflow-hidden\">\n <span className=\"flex gap-1 truncate\" ref={contentRef}>\n {valuesAsChildren.map((child, index) => {\n const tag = (\n <Tag\n key={child.props.value}\n className={cn('cursor-pointer', {\n truncate: index === boundaryIndex,\n hidden: boundaryIndex !== undefined && boundaryIndex !== null ? index > boundaryIndex : false,\n })}\n color={tags ? child.props.color : undefined}\n disabled={disabled}\n icon={child.props.icon}\n onDelete={open ? createClickHandler(child.props.value) : undefined}\n readOnly={readOnly}>\n {child.props.children}\n </Tag>\n );\n\n if (index === boundaryIndex) {\n return (\n <Tooltip key={child.props.value} title={String(child.props.children)}>\n {tag}\n </Tooltip>\n );\n }\n\n return tag;\n })}\n </span>\n {boundaryIndex !== undefined && boundaryIndex !== null && boundaryIndex < valuesAsChildren.length - 1 ? (\n <Tooltip\n title={valuesAsChildren\n .slice(boundaryIndex + 1)\n .map(child => (child ? String(child.props.children) : ''))\n .join(', ')}>\n <Badge className=\"flex-shrink-0\">+{valuesAsChildren.length - (boundaryIndex + 1)}</Badge>\n </Tooltip>\n ) : null}\n </span>\n </Button>\n );\n});\n\nconst matchesValue = (value: undefined | any | any[]) => (child: React.ReactElement<any>) => {\n if (Array.isArray(value)) {\n return value.includes(child.props.value);\n }\n\n return child.props.value === value;\n};\n"],"names":["Trigger","React","forwardRef","Select2Trigger","props","ref","multiple","value","useSelect2Context","Array","isArray","values","undefined","Multiple","Single","Button","Select2TriggerButton","children","onClick","tabIndex","otherProps","disabled","highlighted","invalid","open","readOnly","className","cn","getInputClasses","replace","includes","handleClick","event","preventDefault","role","type","Icon","name","Select2TriggerSingle","buttonProps","tags","contentClassName","currentValue","find","matchesValue","output","Tag","color","icon","Select2TriggerMultiple","setValue","contentRef","useRef","createClickHandler","tagValue","stopPropagation","valuesAsChildren","map","c","ScrollArea","child","key","onDelete","boundaryIndex","current","getIndexOfFirstChildOverflowingParent","index","tag","truncate","hidden","Tooltip","title","String","length","slice","join","Badge"],"mappings":";;;;;;;;;;;MAiBaA,OAAO,gBAAGC,cAAK,CAACC,UAAU,CAAyC,SAASC,cAAc,CAACC,KAAK,EAAEC,GAAG;EAC9G,MAAM;IAAEC,QAAQ;IAAEC;GAAO,GAAGC,iBAAiB,EAAE;EAE/C,I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AG,CAAC,CAAC,CAAS,CACnF,GACV,IAAI,CACL,CACF;AAEjB,CAAC,CAAC;AAEF,MAAMnB,YAAY,GAAIrC,KAA8B,IAAMqD,KAA8B;EACpF,IAAInD,KAAK,CAACC,OAAO,CAACH,KAAK,CAAC,EAAE;IACtB,OAAOA,KAAK,CAACuB,QAAQ,CAAC8B,KAAK,CAACxD,KAAK,CAACG,KAAK,CAAC;;EAG5C,OAAOqD,KAAK,CAACxD,KAAK,CAACG,KAAK,KAAKA,KAAK;AACtC,CAAC;;;;"}
1
+ {"version":3,"file":"Trigger.js","sources":["../../../../../../../../src/components/Select2/components/Trigger.tsx"],"sourcesContent":["import React from 'react';\nimport cn from 'classnames';\nimport { Tag } from '../../Tag/Tag';\nimport { Tooltip } from '../../Tooltip/Tooltip';\nimport { Icon } from '../../Icon/Icon';\nimport { Badge } from '../../Badge/Badge';\nimport { getInputClasses } from '../../Input/util';\nimport { Select2OptionValue } from '../types';\nimport { useSelect2Context } from './Context';\nimport { Select2OptionProps } from './Option';\nimport { getIndexOfFirstChildOverflowingParent } from '../../../utils/dom';\nimport { ScrollArea } from '../../ScrollArea/ScrollArea';\n\ntype Select2TriggerProps = Omit<React.HTMLAttributes<HTMLButtonElement>, 'children' | 'defaultValue' | 'onChange' | 'value'> & {\n children: React.ReactElement<Select2OptionProps>[];\n};\n\nexport const Trigger = React.forwardRef<HTMLButtonElement, Select2TriggerProps>(function Select2Trigger(props, ref) {\n const { multiple, value } = useSelect2Context();\n\n if (Array.isArray(value) || multiple) {\n const values = Array.isArray(value) ? value : value !== undefined ? [value] : undefined;\n return <Multiple {...props} ref={ref} values={values} />;\n }\n\n return <Single {...props} ref={ref} value={value} />;\n});\n\ntype ButtonProps = React.HTMLAttributes<HTMLButtonElement> &\n Omit<Select2TriggerProps, 'children' | 'open' | 'setValue' | 'value'>;\n\nconst Button = React.forwardRef<HTMLButtonElement, ButtonProps>(function Select2TriggerButton(props, ref) {\n const { children, onClick, tabIndex = 0, ...otherProps } = props;\n const { disabled, highlighted, invalid, open, readOnly } = useSelect2Context();\n\n const className = cn(\n 'cursor-pointer !px-1.5',\n getInputClasses({ ...props, disabled, highlighted, invalid, readOnly }).replace('w-full ', ''),\n { 'w-full': !props.className?.includes('w-') },\n props.className\n );\n\n const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {\n if (disabled || readOnly) {\n event.preventDefault();\n return;\n }\n\n if (typeof onClick === 'function') {\n onClick(event);\n }\n };\n\n return (\n <button\n {...otherProps}\n aria-invalid={invalid ? true : undefined}\n aria-readonly={readOnly ? true : undefined}\n className={className}\n disabled={disabled}\n onClick={handleClick}\n ref={ref}\n role=\"combobox\"\n tabIndex={disabled || readOnly ? -1 : tabIndex}\n type=\"button\">\n {children}\n <Icon name={open ? 'chevron-up' : 'chevron-down'} className=\"-mr-1 ml-auto\" />\n </button>\n );\n});\n\ntype SingleProps = Omit<Select2TriggerProps, 'value'> & { value?: Select2OptionValue };\n\nconst Single = React.forwardRef<HTMLButtonElement, SingleProps>(function Select2TriggerSingle(props, ref) {\n const { children, value, ...buttonProps } = props;\n const { disabled, readOnly, tags } = useSelect2Context();\n const contentClassName = cn('truncate flex items-center gap-1');\n\n const currentValue = children.find(matchesValue(value));\n\n let output;\n\n if (currentValue) {\n if (tags) {\n output = (\n <Tag\n className=\"truncate\"\n color={currentValue.props.color}\n disabled={disabled}\n icon={currentValue.props.icon}\n readOnly={readOnly}>\n {currentValue.props.children}\n </Tag>\n );\n } else {\n output = (\n <>\n {currentValue.props.icon ? (\n typeof currentValue.props.icon === 'string' ? (\n <Icon name={currentValue.props.icon} />\n ) : (\n currentValue.props.icon\n )\n ) : null}\n {currentValue.props.children}\n </>\n );\n }\n }\n\n return (\n <Button {...buttonProps} ref={ref}>\n <span className={contentClassName}>{output}</span>\n </Button>\n );\n});\n\ntype MultipleProps = Omit<Select2TriggerProps, 'value'> & {\n values?: Select2OptionValue[];\n};\n\nconst Multiple = React.forwardRef<HTMLButtonElement, MultipleProps>(function Select2TriggerMultiple(props, ref) {\n const { children, values = [], ...buttonProps } = props;\n const { disabled, open, readOnly, setValue, tags } = useSelect2Context();\n const contentRef = React.useRef<HTMLSpanElement>(null);\n\n const createClickHandler = tagValue => event => {\n event?.stopPropagation();\n event?.preventDefault();\n\n if (!disabled && !readOnly) {\n setValue(tagValue);\n }\n };\n const valuesAsChildren = values.map(value =>\n children.find(c => c.props.value === value)\n ) as React.ReactElement<Select2OptionProps>[];\n\n if (open) {\n return (\n <span className=\"relative h-8\">\n <Button {...buttonProps} className={cn('absolute z-20', buttonProps.className)} ref={ref}>\n <ScrollArea className=\"my-1 flex max-h-[5.5rem] flex-col\">\n <span className=\"flex flex-wrap gap-1\">\n {valuesAsChildren.map(child => (\n <Tag\n key={child.props.value}\n className=\"truncate\"\n color={tags ? child.props.color : undefined}\n disabled={disabled}\n icon={child.props.icon}\n onDelete={open ? createClickHandler(child.props.value) : undefined}\n readOnly={readOnly}>\n {child.props.children}\n </Tag>\n ))}\n </span>\n </ScrollArea>\n </Button>\n </span>\n );\n }\n\n const boundaryIndex = contentRef.current ? getIndexOfFirstChildOverflowingParent(contentRef.current, 30) : undefined;\n\n return (\n <Button {...buttonProps} ref={ref}>\n <span className=\"relative flex items-center gap-1 overflow-hidden\">\n <span className=\"flex gap-1 truncate\" ref={contentRef}>\n {valuesAsChildren.map((child, index) => {\n const tag = (\n <Tag\n key={child.props.value}\n className={cn('cursor-pointer', {\n truncate: index === boundaryIndex,\n hidden: boundaryIndex !== undefined && boundaryIndex !== null ? index > boundaryIndex : false,\n })}\n color={tags ? child.props.color : undefined}\n disabled={disabled}\n icon={child.props.icon}\n onDelete={open ? createClickHandler(child.props.value) : undefined}\n readOnly={readOnly}>\n {child.props.children}\n </Tag>\n );\n\n if (index === boundaryIndex) {\n return (\n <Tooltip key={child.props.value} title={String(child.props.children)}>\n {tag}\n </Tooltip>\n );\n }\n\n return tag;\n })}\n </span>\n {boundaryIndex !== undefined && boundaryIndex !== null && boundaryIndex < valuesAsChildren.length - 1 ? (\n <Tooltip\n title={valuesAsChildren\n .slice(boundaryIndex + 1)\n .map(child => (child ? String(child.props.children) : ''))\n .join(', ')}>\n <Badge className=\"flex-shrink-0\">+{valuesAsChildren.length - (boundaryIndex + 1)}</Badge>\n </Tooltip>\n ) : null}\n </span>\n </Button>\n );\n});\n\nconst matchesValue = (value: undefined | any | any[]) => (child: React.ReactElement<any>) => {\n if (Array.isArray(value)) {\n return value.includes(child.props.value);\n }\n\n return child.props.value === value;\n};\n"],"names":["Trigger","React","forwardRef","Select2Trigger","props","ref","multiple","value","useSelect2Context","Array","isArray","values","undefined","Multiple","Single","Button","Select2TriggerButton","children","onClick","tabIndex","otherProps","disabled","highlighted","invalid","open","readOnly","className","cn","getInputClasses","replace","includes","handleClick","event","preventDefault","role","type","Icon","name","Select2TriggerSingle","buttonProps","tags","contentClassName","currentValue","find","matchesValue","output","Tag","color","icon","Select2TriggerMultiple","setValue","contentRef","useRef","createClickHandler","tagValue","stopPropagation","valuesAsChildren","map","c","ScrollArea","child","key","onDelete","boundaryIndex","current","getIndexOfFirstChildOverflowingParent","index","tag","truncate","hidden","Tooltip","title","String","length","slice","join","Badge"],"mappings":";;;;;;;;;;;MAiBaA,OAAO,gBAAGC,cAAK,CAACC,UAAU,CAAyC,SAASC,cAAc,CAACC,KAAK,EAAEC,GAAG;EAC9G,MAAM;IAAEC,QAAQ;IAAEC;GAAO,GAAGC,iBAAiB,EAAE;EAE/C,IAAIC,KAAK,CAACC,OAAO,CAACH,KAAK,CAAC,IAAID,QAAQ,EAAE;IAClC,MAAMK,MAAM,GAAGF,KAAK,CAACC,OAAO,CAACH,KAAK,CAAC,GAAGA,KAAK,GAAGA,KAAK,KAAKK,SAAS,GAAG,CAACL,KAAK,CAAC,GAAGK,SAAS;IACvF,oBAAOX,6BAACY,QAAQ,oBAAKT,KAAK;MAAEC,GAAG,EAAEA,GAAG;MAAEM,MAAM,EAAEA;OAAU;;EAG5D,oBAAOV,6BAACa,MAAM,oBA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/input.js';
3
3
  import { useMergedRef } from '../../../hooks/useMergedRef.js';
4
4
  import { isAriaDirectionKey } from '../../../utils/aria.js';
5
5
 
6
- const getOptions = (collection, selector) => collection.querySelectorAll(selector);
6
+ const getOptionsFromCollection = (collection, selector) => collection.querySelectorAll(selector);
7
7
  // we use javascript to set attributes (rather than cloning children and adding them)
8
8
  // so that we can support nesting (e.g. groups) - child elements that aren't options.
9
9
  // without doing this we would have to unwrap and flatten all groups
10
10
  const Root = /*#__PURE__*/React__default.forwardRef(function CollectionRoot(props, ref) {
11
11
  const {
12
- selector,
12
+ querySelector,
13
13
  tabIndex = 0,
14
14
  ...otherProps
15
15
  } = props;
16
16
  const internalRef = useMergedRef(ref);
17
17
  const [activeIndex, setActiveIndex] = React__default.useState();
18
- const toggleCurrent = collection => {
18
+ const lastLengthRef = React__default.useRef(0);
19
+ const setActiveOption = (index, collection, option) => {
19
20
  var _collection$querySele;
20
21
  (_collection$querySele = collection.querySelector(`[aria-current]`)) === null || _collection$querySele === void 0 ? void 0 : _collection$querySele.removeAttribute('aria-current');
21
- if (activeIndex !== undefined) {
22
- var _getOptions;
23
- const option = (_getOptions = getOptions(collection, selector)) === null || _getOptions === void 0 ? void 0 : _getOptions.item(activeIndex);
24
- if (option) {
25
- option.setAttribute('aria-current', 'true');
26
- option.scrollIntoView({
27
- block: 'nearest'
28
- });
29
- }
30
- }
22
+ option.setAttribute('aria-current', 'true');
23
+ option.scrollIntoView({
24
+ block: 'nearest'
25
+ });
26
+ setActiveIndex(index);
31
27
  };
32
28
  const setActiveIndexByElement = React__default.useCallback(option => {
33
29
  if (internalRef.current) {
34
- if (option.matches(selector)) {
35
- const options = getOptions(internalRef.current, selector);
30
+ if (option.matches(querySelector)) {
31
+ const options = getOptionsFromCollection(internalRef.current, querySelector);
36
32
  const nextActiveIndex = Array.from(options).indexOf(option);
37
33
  if (nextActiveIndex > -1) {
38
- setActiveIndex(nextActiveIndex);
34
+ setActiveOption(nextActiveIndex, internalRef.current, option);
39
35
  }
40
36
  }
41
37
  }
42
- }, [internalRef.current]);
38
+ }, [internalRef.current, querySelector]);
43
39
  React__default.useEffect(() => {
44
40
  if (internalRef.current) {
45
41
  internalRef.current.setActiveIndex = setActiveIndexByElement;
46
42
  }
47
43
  }, [internalRef.current]);
48
- // set/remove appropriate aria-current attributes
49
- // we do this in a hook because we expose setActiveIndex on the ref
50
- React__default.useEffect(() => {
51
- if (internalRef.current) {
52
- toggleCurrent(internalRef.current);
53
- }
54
- }, [activeIndex]);
55
- // set the initial active index on mount
56
44
  React__default.useEffect(() => {
57
45
  if (internalRef.current) {
58
- const selected = internalRef.current.querySelectorAll(`[aria-selected]`);
59
- if (selected.length === 1) {
60
- const options = getOptions(internalRef.current, selector);
61
- if (options) {
62
- const selectedIndex = Array.from(options).indexOf(selected.item(0));
63
- if (selectedIndex > -1) {
64
- setActiveIndex(selectedIndex);
46
+ const options = getOptionsFromCollection(internalRef.current, querySelector);
47
+ if (options.length && options.length !== lastLengthRef.current) {
48
+ const selected = internalRef.current.querySelectorAll(`[aria-selected]`);
49
+ if (selected.length === 1) {
50
+ if (options) {
51
+ const firstSelected = selected.item(0);
52
+ const selectedIndex = Array.from(options).indexOf(firstSelected);
53
+ if (selectedIndex > -1) {
54
+ setActiveOption(selectedIndex, internalRef.current, firstSelected);
55
+ }
65
56
  }
57
+ } else {
58
+ // multiple selected or none selected should go to 0
59
+ setActiveOption(0, internalRef.current, options.item(0));
66
60
  }
67
- } else {
68
- // multiple selected or none selected should go to 0
69
- setActiveIndex(0);
70
- }
71
- }
72
- }, []);
73
- // if children length changes, make sure we still have a valid active index (e.g. searching/filtering or adding a new item)
74
- React__default.useEffect(() => {
75
- if (internalRef.current) {
76
- // make sure index and dom are synced
77
- toggleCurrent(internalRef.current);
78
- if (activeIndex !== undefined && activeIndex > React__default.Children.count(props.children)) {
79
- setActiveIndex(0);
80
61
  }
62
+ lastLengthRef.current = options.length;
81
63
  }
82
64
  }, [props.children]);
83
65
  const handleClick = event => {
84
- setActiveIndexByElement(event.target);
66
+ const option = event.target;
67
+ if (option.matches(querySelector)) {
68
+ const options = getOptionsFromCollection(event.currentTarget, querySelector);
69
+ const nextActiveIndex = Array.from(options).indexOf(option);
70
+ if (nextActiveIndex > -1) {
71
+ setActiveOption(nextActiveIndex, event.currentTarget, option);
72
+ }
73
+ }
85
74
  };
86
75
  const handleKeyDown = event => {
87
76
  // this stops the event dispatched to the option rebounding back and starting an infinite loop
88
77
  if (event.target !== event.currentTarget) {
89
78
  return;
90
79
  }
91
- const options = getOptions(event.currentTarget, selector);
80
+ const options = getOptionsFromCollection(event.currentTarget, querySelector);
92
81
  if (options) {
93
82
  if (isAriaDirectionKey(event)) {
94
83
  const nextActiveIndex = getNextEnabledItem(event, options, activeIndex);
95
84
  if (nextActiveIndex !== undefined && nextActiveIndex !== activeIndex) {
96
85
  event.preventDefault();
97
- setActiveIndex(nextActiveIndex);
86
+ setActiveOption(nextActiveIndex, event.currentTarget, options.item(nextActiveIndex));
98
87
  }
99
88
  } else if (activeIndex !== undefined) {
100
89
  // forward events onto the underlying option - this lets consumers place onKeyDown handlers on their own components
@@ -106,7 +95,7 @@ const Root = /*#__PURE__*/React__default.forwardRef(function CollectionRoot(prop
106
95
  onClick: handleClick,
107
96
  onKeyDown: handleKeyDown,
108
97
  ref: internalRef,
109
- tabIndex: tabIndex !== null && tabIndex !== void 0 ? tabIndex : 0
98
+ tabIndex: tabIndex
110
99
  }));
111
100
  });
112
101
  const getNextIndexFromKeycode = (event, length, activeIndex) => {
@@ -1 +1 @@
1
- {"version":3,"file":"Root.js","sources":["../../../../../../../../src/primitives/Collection/components/Root.tsx"],"sourcesContent":["import React from 'react';\nimport { useMergedRef } from '../../../hooks/useMergedRef';\nimport { isAriaDirectionKey } from '../../../utils/aria';\nimport { createCustomKeyboardEvent } from '../../../utils/input';\n\n/* This component provides a keyboard navigable collection primitive for use in lists\n * It is unlikely you need to edit this component\n */\n\nexport type CollectionProps = React.HTMLAttributes<HTMLDivElement> & {\n selector: string;\n};\n\nexport type CollectionRef = HTMLDivElement & {\n setActiveIndex: (option: HTMLDivElement) => void;\n};\n\nconst getOptions = (collection: HTMLDivElement, selector: string): NodeListOf<Element> => collection.querySelectorAll(selector);\n\n// we use javascript to set attributes (rather than cloning children and adding them)\n// so that we can support nesting (e.g. groups) - child elements that aren't options.\n// without doing this we would have to unwrap and flatten all groups\nexport const Root = React.forwardRef<CollectionRef, CollectionProps>(function CollectionRoot(props, ref) {\n const { selector, tabIndex = 0, ...otherProps } = props;\n const internalRef = useMergedRef<CollectionRef>(ref);\n const [activeIndex, setActiveIndex] = React.useState<undefined | number>();\n\n const toggleCurrent = (collection: HTMLDivElement) => {\n collection.querySelector(`[aria-current]`)?.removeAttribute('aria-current');\n\n if (activeIndex !== undefined) {\n const option = getOptions(collection, selector)?.item(activeIndex);\n\n if (option) {\n option.setAttribute('aria-current', 'true');\n option.scrollIntoView({ block: 'nearest' });\n }\n }\n };\n\n const setActiveIndexByElement = React.useCallback(\n (option: HTMLDivElement) => {\n if (internalRef.current) {\n if (option.matches(selector)) {\n const options = getOptions(internalRef.current, selector);\n const nextActiveIndex = Array.from(options).indexOf(option);\n\n if (nextActiveIndex > -1) {\n setActiveIndex(nextActiveIndex);\n }\n }\n }\n },\n [internalRef.current]\n );\n\n React.useEffect(() => {\n if (internalRef.current) {\n internalRef.current.setActiveIndex = setActiveIndexByElement;\n }\n }, [internalRef.current]);\n\n // set/remove appropriate aria-current attributes\n // we do this in a hook because we expose setActiveIndex on the ref\n React.useEffect(() => {\n if (internalRef.current) {\n toggleCurrent(internalRef.current);\n }\n }, [activeIndex]);\n\n // set the initial active index on mount\n React.useEffect(() => {\n if (internalRef.current) {\n const selected = internalRef.current.querySelectorAll(`[aria-selected]`);\n\n if (selected.length === 1) {\n const options = getOptions(internalRef.current, selector);\n\n if (options) {\n const selectedIndex = Array.from(options).indexOf(selected.item(0));\n\n if (selectedIndex > -1) {\n setActiveIndex(selectedIndex);\n }\n }\n } else {\n // multiple selected or none selected should go to 0\n setActiveIndex(0);\n }\n }\n }, []);\n\n // if children length changes, make sure we still have a valid active index (e.g. searching/filtering or adding a new item)\n React.useEffect(() => {\n if (internalRef.current) {\n // make sure index and dom are synced\n toggleCurrent(internalRef.current);\n\n if (activeIndex !== undefined && activeIndex > React.Children.count(props.children)) {\n setActiveIndex(0);\n }\n }\n }, [props.children]);\n\n const handleClick = (event: React.MouseEvent<HTMLDivElement>) => {\n setActiveIndexByElement(event.target as HTMLDivElement);\n };\n\n const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {\n // this stops the event dispatched to the option rebounding back and starting an infinite loop\n if (event.target !== event.currentTarget) {\n return;\n }\n\n const options = getOptions(event.currentTarget, selector);\n\n if (options) {\n if (isAriaDirectionKey(event)) {\n const nextActiveIndex = getNextEnabledItem(event, options, activeIndex);\n\n if (nextActiveIndex !== undefined && nextActiveIndex !== activeIndex) {\n event.preventDefault();\n setActiveIndex(nextActiveIndex);\n }\n } else if (activeIndex !== undefined) {\n // forward events onto the underlying option - this lets consumers place onKeyDown handlers on their own components\n options\n .item(activeIndex)\n .dispatchEvent(createCustomKeyboardEvent(event as React.KeyboardEvent<HTMLInputElement>));\n }\n }\n };\n\n return <div {...otherProps} onClick={handleClick} onKeyDown={handleKeyDown} ref={internalRef} tabIndex={tabIndex ?? 0} />;\n});\n\nexport const getNextIndexFromKeycode = (\n event: React.KeyboardEvent,\n length: number,\n activeIndex: number | undefined\n): number | undefined => {\n switch (event.key) {\n case 'ArrowUp':\n return activeIndex === undefined ? length - 1 : activeIndex > 0 ? activeIndex - 1 : activeIndex;\n\n case 'ArrowDown':\n return activeIndex === undefined ? 0 : activeIndex < length - 1 ? activeIndex + 1 : activeIndex;\n\n case 'Home':\n return 0;\n\n case 'End':\n return length - 1;\n\n default:\n return;\n }\n};\n\nexport const getNextEnabledItem = (\n event: React.KeyboardEvent<HTMLElement>,\n options: NodeListOf<Element>,\n activeIndex: number | undefined,\n recurse = true\n): number | undefined => {\n const nextIndex = getNextIndexFromKeycode(event, options.length, activeIndex);\n\n if (nextIndex !== undefined) {\n if (nextIndex === activeIndex) {\n return activeIndex;\n } else if (options.item(nextIndex) && isSkippableItem(options.item(nextIndex))) {\n // check in the other direction if the first or last item is disabled,\n // but prevent infinite loops if all elements are disabled by disabling recursion\n if (recurse) {\n if (nextIndex === 0) {\n return getNextEnabledItem(\n new KeyboardEvent(event.type, { ...(event as any), key: 'ArrowDown' }) as any,\n options,\n nextIndex,\n false\n );\n } else if (nextIndex === options.length - 1) {\n return getNextEnabledItem(\n new KeyboardEvent(event.type, { ...(event as any), key: 'ArrowUp' }) as any,\n options,\n nextIndex,\n false\n );\n }\n }\n\n return getNextEnabledItem(event, options, nextIndex, recurse);\n }\n }\n\n return nextIndex;\n};\n\nconst isSkippableItem = (element: Element) => {\n return (\n element.getAttribute('role') === 'presentation' ||\n !!element.hasAttribute('disabled') ||\n !!element.getAttribute('aria-disabled') ||\n !!element.getAttribute('aria-hidden')\n );\n};\n"],"names":["getOptions","collection","selector","querySelectorAll","Root","React","forwardRef","CollectionRoot","props","ref","tabIndex","otherProps","internalRef","useMergedRef","activeIndex","setActiveIndex","useState","toggleCurrent","querySelector","removeAttribute","undefined","option","item","setAttribute","scrollIntoView","block","setActiveIndexByElement","useCallback","current","matches","options","nextActiveIndex","Array","from","indexOf","useEffect","selected","length","selectedIndex","Children","count","children","handleClick","event","target","handleKeyDown","currentTarget","isAriaDirectionKey","getNextEnabledItem","preventDefault","dispatchEvent","createCustomKeyboardEvent","onClick","onKeyDown","getNextIndexFromKeycode","key","recurse","nextIndex","isSkippableItem","KeyboardEvent","type","element","getAttribute","hasAttribute"],"mappings":";;;;;AAiBA,MAAMA,UAAU,GAAG,CAACC,UAA0B,EAAEC,QAAgB,KAA0BD,UAAU,CAACE,gBAAgB,CAACD,QAAQ,CAAC;AAE/H;AACA;AACA;MACaE,IAAI,gBAAGC,cAAK,CAACC,UAAU,CAAiC,SAASC,cAAc,CAACC,K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C/C,CAAC,CAACD,OAAO,CAACE,YAAY,CAAC,UAAU,CAAC,IAClC,CAAC,CAACF,OAAO,CAACC,YAAY,CAAC,eAAe,CAAC,IACvC,CAAC,CAACD,OAAO,CAACC,YAAY,CAAC,aAAa,CAAC;AAE7C,CAAC;;;;"}
1
+ {"version":3,"file":"Root.js","sources":["../../../../../../../../src/primitives/Collection/components/Root.tsx"],"sourcesContent":["import React from 'react';\nimport { useMergedRef } from '../../../hooks/useMergedRef';\nimport { isAriaDirectionKey } from '../../../utils/aria';\nimport { createCustomKeyboardEvent } from '../../../utils/input';\n\n/* This component provides a keyboard navigable collection primitive for use in lists\n * It is unlikely you need to edit this component\n */\n\nexport type CollectionProps = React.HTMLAttributes<HTMLDivElement> & {\n querySelector: string;\n};\n\nexport type CollectionRef = HTMLDivElement & {\n setActiveIndex: (option: HTMLDivElement) => void;\n};\n\nconst getOptionsFromCollection = (collection: HTMLDivElement, selector: string): NodeListOf<Element> =>\n collection.querySelectorAll(selector);\n\n// we use javascript to set attributes (rather than cloning children and adding them)\n// so that we can support nesting (e.g. groups) - child elements that aren't options.\n// without doing this we would have to unwrap and flatten all groups\nexport const Root = React.forwardRef<CollectionRef, CollectionProps>(function CollectionRoot(props, ref) {\n const { querySelector, tabIndex = 0, ...otherProps } = props;\n const internalRef = useMergedRef<CollectionRef>(ref);\n const [activeIndex, setActiveIndex] = React.useState<number | undefined>();\n const lastLengthRef = React.useRef(0);\n\n const setActiveOption = (index: number, collection: HTMLDivElement, option: Element) => {\n collection.querySelector(`[aria-current]`)?.removeAttribute('aria-current');\n option.setAttribute('aria-current', 'true');\n option.scrollIntoView({ block: 'nearest' });\n setActiveIndex(index);\n };\n\n const setActiveIndexByElement = React.useCallback(\n (option: HTMLDivElement) => {\n if (internalRef.current) {\n if (option.matches(querySelector)) {\n const options = getOptionsFromCollection(internalRef.current, querySelector);\n const nextActiveIndex = Array.from(options).indexOf(option);\n\n if (nextActiveIndex > -1) {\n setActiveOption(nextActiveIndex, internalRef.current, option);\n }\n }\n }\n },\n [internalRef.current, querySelector]\n );\n\n React.useEffect(() => {\n if (internalRef.current) {\n internalRef.current.setActiveIndex = setActiveIndexByElement;\n }\n }, [internalRef.current]);\n\n React.useEffect(() => {\n if (internalRef.current) {\n const options = getOptionsFromCollection(internalRef.current, querySelector);\n\n if (options.length && options.length !== lastLengthRef.current) {\n const selected = internalRef.current.querySelectorAll(`[aria-selected]`);\n\n if (selected.length === 1) {\n if (options) {\n const firstSelected = selected.item(0);\n const selectedIndex = Array.from(options).indexOf(firstSelected);\n\n if (selectedIndex > -1) {\n setActiveOption(selectedIndex, internalRef.current, firstSelected);\n }\n }\n } else {\n // multiple selected or none selected should go to 0\n setActiveOption(0, internalRef.current, options.item(0));\n }\n }\n\n lastLengthRef.current = options.length;\n }\n }, [props.children]);\n\n const handleClick = (event: React.MouseEvent<HTMLDivElement>) => {\n const option = event.target as HTMLElement;\n\n if (option.matches(querySelector)) {\n const options = getOptionsFromCollection(event.currentTarget, querySelector);\n const nextActiveIndex = Array.from(options).indexOf(option);\n\n if (nextActiveIndex > -1) {\n setActiveOption(nextActiveIndex, event.currentTarget, option);\n }\n }\n };\n\n const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {\n // this stops the event dispatched to the option rebounding back and starting an infinite loop\n if (event.target !== event.currentTarget) {\n return;\n }\n\n const options = getOptionsFromCollection(event.currentTarget, querySelector);\n\n if (options) {\n if (isAriaDirectionKey(event)) {\n const nextActiveIndex = getNextEnabledItem(event, options, activeIndex);\n\n if (nextActiveIndex !== undefined && nextActiveIndex !== activeIndex) {\n event.preventDefault();\n setActiveOption(nextActiveIndex, event.currentTarget, options.item(nextActiveIndex));\n }\n } else if (activeIndex !== undefined) {\n // forward events onto the underlying option - this lets consumers place onKeyDown handlers on their own components\n options\n .item(activeIndex)\n .dispatchEvent(createCustomKeyboardEvent(event as React.KeyboardEvent<HTMLInputElement>));\n }\n }\n };\n\n return <div {...otherProps} onClick={handleClick} onKeyDown={handleKeyDown} ref={internalRef} tabIndex={tabIndex} />;\n});\n\nexport const getNextIndexFromKeycode = (\n event: React.KeyboardEvent,\n length: number,\n activeIndex: number | undefined\n): number | undefined => {\n switch (event.key) {\n case 'ArrowUp':\n return activeIndex === undefined ? length - 1 : activeIndex > 0 ? activeIndex - 1 : activeIndex;\n\n case 'ArrowDown':\n return activeIndex === undefined ? 0 : activeIndex < length - 1 ? activeIndex + 1 : activeIndex;\n\n case 'Home':\n return 0;\n\n case 'End':\n return length - 1;\n\n default:\n return;\n }\n};\n\nexport const getNextEnabledItem = (\n event: React.KeyboardEvent<HTMLElement>,\n options: NodeListOf<Element>,\n activeIndex: number | undefined,\n recurse = true\n): number | undefined => {\n const nextIndex = getNextIndexFromKeycode(event, options.length, activeIndex);\n\n if (nextIndex !== undefined) {\n if (nextIndex === activeIndex) {\n return activeIndex;\n } else if (options.item(nextIndex) && isSkippableItem(options.item(nextIndex))) {\n // check in the other direction if the first or last item is disabled,\n // but prevent infinite loops if all elements are disabled by disabling recursion\n if (recurse) {\n if (nextIndex === 0) {\n return getNextEnabledItem(\n new KeyboardEvent(event.type, { ...(event as any), key: 'ArrowDown' }) as any,\n options,\n nextIndex,\n false\n );\n } else if (nextIndex === options.length - 1) {\n return getNextEnabledItem(\n new KeyboardEvent(event.type, { ...(event as any), key: 'ArrowUp' }) as any,\n options,\n nextIndex,\n false\n );\n }\n }\n\n return getNextEnabledItem(event, options, nextIndex, recurse);\n }\n }\n\n return nextIndex;\n};\n\nconst isSkippableItem = (element: Element) => {\n return (\n element.getAttribute('role') === 'presentation' ||\n !!element.hasAttribute('disabled') ||\n !!element.getAttribute('aria-disabled') ||\n !!element.getAttribute('aria-hidden')\n );\n};\n"],"names":["getOptionsFromCollection","collection","selector","querySelectorAll","Root","React","forwardRef","CollectionRoot","props","ref","querySelector","tabIndex","otherProps","internalRef","useMergedRef","activeIndex","setActiveIndex","useState","lastLengthRef","useRef","setActiveOption","index","option","removeAttribute","setAttribute","scrollIntoView","block","setActiveIndexByElement","useCallback","current","matches","options","nextActiveIndex","Array","from","indexOf","useEffect","length","selected","firstSelected","item","selectedIndex","children","handleClick","event","target","currentTarget","handleKeyDown","isAriaDirectionKey","getNextEnabledItem","undefined","preventDefault","dispatchEvent","createCustomKeyboardEvent","onClick","onKeyDown","getNextIndexFromKeycode","key","recurse","nextIndex","isSkippableItem","KeyboardEvent","type","element","getAttribute","hasAttribute"],"mappings":";;;;;AAiBA,MAAMA,wBAAwB,GAAG,CAACC,UAA0B,EAAEC,QAAgB,KAC1ED,UAAU,CAACE,gBAAgB,CAACD,QAAQ,CAAC;AAEzC;AACA;AACA;MACaE,IAAI,gBAAGC,cAAK,CAACC,UAAU,CAAiC,SAASC,cAAc,CAACC,KAAK,EAAEC,GAAG;EACnG,MAAM;IAAEC,aAAa;IAAEC,QAAQ,GAAG,CAAC;IAAE,GAAGC;GAAY,GAAGJ,KAAK;EAC5D,MAAMK,WAAW,GAAGC,YAAY,CAAgBL,GAAG,CAAC;EACpD,MAAM,CAACM,WAAW,EAAEC,cAAc,CAAC,GAAGX,cAAK,CAACY,QAAQ,EAAsB;EAC1E,MAAMC,aAAa,GAAGb,cAAK,CAACc,MAAM,CAAC,CAAC,CAAC;EAErC,MAAMC,eAAe,GAAG,CAACC,KAAa,EAAEpB,UAA0B,EAAEqB,MAAe;;IAC/E,yBAAArB,UAAU,CAACS,aAAa,iBAAiB,CAAC,0DAA1C,sBAA4Ca,eAAe,CAAC,cAAc,CAAC;IAC3ED,MAAM,CAACE,YAAY,CAAC,cAAc,EAAE,MAAM,CAAC;IAC3CF,MAAM,CAACG,cAAc,CAAC;MAAEC,KAAK,EAAE;KAAW,CAAC;IAC3CV,cAAc,CAACK,KAAK,CAAC;GACxB;EAED,MAAMM,uBAAuB,GAAGtB,cAAK,CAACuB,WAAW,CAC5CN,MAAsB;IACnB,IAAIT,WAAW,CAACgB,OAAO,EAAE;MACrB,IAAIP,MAAM,CAACQ,OAAO,CAACpB,aAAa,CAAC,E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AID,OAAO,EAAE;QACT,IAAIC,SAAS,KAAK,CAAC,EAAE;UACjB,OAAOV,kBAAkB,CACrB,IAAIY,aAAa,CAACjB,KAAK,CAACkB,IAAI,EAAE;YAAE,GAAIlB,KAAa;YAAEa,GAAG,EAAE;WAAa,CAAQ,EAC7E1B,OAAO,EACP4B,SAAS,EACT,KAAK,CACR;SACJ,MAAM,IAAIA,SAAS,KAAK5B,OAAO,CAACM,MAAM,GAAG,CAAC,EAAE;UACzC,OAAOY,kBAAkB,CACrB,IAAIY,aAAa,CAACjB,KAAK,CAACkB,IAAI,EAAE;YAAE,GAAIlB,KAAa;YAAEa,GAAG,EAAE;WAAW,CAAQ,EAC3E1B,OAAO,EACP4B,SAAS,EACT,KAAK,CACR;;;MAIT,OAAOV,kBAAkB,CAACL,KAAK,EAAEb,OAAO,EAAE4B,SAAS,EAAED,OAAO,CAAC;;;EAIrE,OAAOC,SAAS;AACpB;AAEA,MAAMC,eAAe,GAAIG,OAAgB;EACrC,OACIA,OAAO,CAACC,YAAY,CAAC,MAAM,CAAC,KAAK,cAAc,IAC/C,CAAC,CAACD,OAAO,CAACE,YAAY,CAAC,UAAU,CAAC,IAClC,CAAC,CAACF,OAAO,CAACC,YAAY,CAAC,eAAe,CAAC,IACvC,CAAC,CAACD,OAAO,CAACC,YAAY,CAAC,aAAa,CAAC;AAE7C,CAAC;;;;"}
@@ -33,7 +33,7 @@ const Root = /*#__PURE__*/React__default.forwardRef(function Listbox2(props, ref
33
33
  id: id,
34
34
  ref: ref,
35
35
  role: "listbox",
36
- selector: customSelector ? `${DEFAULT_SELECTOR}, ${customSelector}` : DEFAULT_SELECTOR
36
+ querySelector: customSelector ? `${DEFAULT_SELECTOR}, ${customSelector}` : DEFAULT_SELECTOR
37
37
  }), children)));
38
38
  });
39
39
  const createListboxValueSetter = (multiple, setValue) => nextValue => {
@@ -1 +1 @@
1
- {"version":3,"file":"Root.js","sources":["../../../../../../../../src/primitives/Listbox2/components/Root.tsx"],"sourcesContent":["import React from 'react';\nimport { useId } from '../../../hooks/useId';\nimport * as CollectionPrimitive from '../../Collection/Collection';\nimport { Listbox2Value } from '../types';\nimport { Listbox2Context } from './Context';\n\nexport type Listbox2Props = React.HTMLAttributes<HTMLDivElement> & {\n customSelector?: string;\n disabled?: boolean;\n multiple?: boolean;\n readOnly?: boolean;\n setValue: (value: Listbox2Value) => void;\n value?: Listbox2Value;\n};\n\nconst DEFAULT_SELECTOR = '[role=\"option\"]';\n\nexport const Root = React.forwardRef<CollectionPrimitive.CollectionRef, Listbox2Props>(function Listbox2(props, ref) {\n const {\n children,\n customSelector,\n disabled = false,\n id: nativeId,\n multiple,\n readOnly = false,\n setValue,\n title,\n value,\n ...otherProps\n } = props;\n const id = useId(nativeId);\n\n const context = React.useMemo(\n () => ({\n disabled,\n readOnly,\n setValue,\n value,\n }),\n [disabled, readOnly, value]\n );\n\n return (\n <Listbox2Context.Provider value={context}>\n <div data-taco=\"listbox2\">\n <CollectionPrimitive.Root\n {...otherProps}\n aria-multiselectable={multiple ? true : undefined}\n id={id}\n ref={ref}\n role=\"listbox\"\n selector={customSelector ? `${DEFAULT_SELECTOR}, ${customSelector}` : DEFAULT_SELECTOR}>\n {children}\n </CollectionPrimitive.Root>\n </div>\n </Listbox2Context.Provider>\n );\n});\n\nexport const createListboxValueSetter =\n (multiple: boolean, setValue: React.Dispatch<React.SetStateAction<Listbox2Value | undefined>>) =>\n (nextValue: Listbox2Value) => {\n setValue(value => {\n if (Array.isArray(nextValue)) {\n return nextValue;\n }\n\n if (multiple) {\n if (value === undefined) {\n return [nextValue];\n } else if (Array.isArray(value)) {\n if (value.includes(nextValue)) {\n return value.filter(v => v !== nextValue);\n }\n\n return [...value, nextValue];\n } else if (value === nextValue) {\n return [];\n }\n\n return [value, nextValue];\n }\n\n return nextValue;\n });\n };\n"],"names":["DEFAULT_SELECTOR","Root","React","forwardRef","Listbox2","props","ref","children","customSelector","disabled","id","nativeId","multiple","readOnly","setValue","title","value","otherProps","useId","context","useMemo","Listbox2Context","Provider","CollectionPrimitive","undefined","role","selector","createListboxValueSetter","nextValue","Array","isArray","includes","filter","v"],"mappings":";;;;;AAeA,MAAMA,gBAAgB,GAAG,iBAAiB;MAE7BC,IAAI,gBAAGC,cAAK,CAACC,UAAU,CAAmD,SAASC,QAAQ,CAACC,KAAK,EAAEC,GAAG;EAC/G,MAAM;IACFC,QAAQ;IACRC,cAAc;IACdC,QAAQ,GAAG,KAAK;IAChBC,EAAE,EAAEC,QAAQ;IACZC,QAAQ;IACRC,QAAQ,GAAG,KAAK;IAChBC,QAAQ;IACRC,KAAK;IACLC,KAAK;IACL,GAAGC;GACN,GAAGZ,KAAK;EACT,MAAMK,EAAE,GAAGQ,KAAK,CAACP,QAAQ,CAAC;EAE1B,MAAMQ,OAAO,GAAGjB,cAAK,CAACkB,OAAO,CACzB,OAAO;IACHX,QAAQ;IACRI,QAAQ;IACRC,QAAQ;IACRE;GACH,CAAC,EACF,CAACP,QAAQ,EAAEI,QAAQ,EAAEG,KAAK,CAAC,CAC9B;EAED,oBACId,6BAACmB,eAAe,CAACC,QAAQ;IAACN,KAAK,EAAEG;kBAC7BjB;iBAAe;kBACXA,6BAACqB,MAAwB,oBACjBN,UAAU;4BACQL,QAAQ,GAAG,IAAI,GAAGY,SAAS;IACjDd,EAAE,EAAEA,EAAE;IACNJ,GAAG,EAAEA,GAAG;IACRmB,IAAI,EAAC,SAAS;IACdC,QAAQ,EAAElB,cAAc,MAAMR,qBAAqBQ,gBAAgB,GAAGR;MACrEO,QAAQ,CACc,CACzB,CACiB;AAEnC,CAAC;MAEYoB,wBAAwB,GACjC,CAACf,QAAiB,EAAEE,QAAyE,KAC5Fc,SAAwB;EACrBd,QAAQ,CAACE,KAAK;IACV,IAAIa,KAAK,CAACC,OAAO,CAACF,SAAS,CAAC,EAAE;MAC1B,OAAOA,SAAS;;IAGpB,IAAIhB,QAAQ,EAAE;MACV,IAAII,KAAK,KAAKQ,SAAS,EAAE;QACrB,OAAO,CAACI,SAAS,CAAC;OACrB,MAAM,IAAIC,KAAK,CAACC,OAAO,CAACd,KAAK,CAAC,EAAE;QAC7B,IAAIA,KAAK,CAACe,QAAQ,CAACH,SAAS,CAAC,EAAE;UAC3B,OAAOZ,KAAK,CAACgB,MAAM,CAACC,CAAC,IAAIA,CAAC,KAAKL,SAAS,CAAC;;QAG7C,OAAO,CAAC,GAAGZ,KAAK,EAAEY,SAAS,CAAC;OAC/B,MAAM,IAAIZ,KAAK,KAAKY,SAAS,EAAE;QAC5B,OAAO,EAAE;;MAGb,OAAO,CAACZ,KAAK,EAAEY,SAAS,CAAC;;IAG7B,OAAOA,SAAS;GACnB,CAAC;AACN;;;;"}
1
+ {"version":3,"file":"Root.js","sources":["../../../../../../../../src/primitives/Listbox2/components/Root.tsx"],"sourcesContent":["import React from 'react';\nimport { useId } from '../../../hooks/useId';\nimport * as CollectionPrimitive from '../../Collection/Collection';\nimport { Listbox2Value } from '../types';\nimport { Listbox2Context } from './Context';\n\nexport type Listbox2Props = React.HTMLAttributes<HTMLDivElement> & {\n customSelector?: string;\n disabled?: boolean;\n multiple?: boolean;\n readOnly?: boolean;\n setValue: (value: Listbox2Value) => void;\n value?: Listbox2Value;\n};\n\nconst DEFAULT_SELECTOR = '[role=\"option\"]';\n\nexport const Root = React.forwardRef<CollectionPrimitive.CollectionRef, Listbox2Props>(function Listbox2(props, ref) {\n const {\n children,\n customSelector,\n disabled = false,\n id: nativeId,\n multiple,\n readOnly = false,\n setValue,\n title,\n value,\n ...otherProps\n } = props;\n const id = useId(nativeId);\n\n const context = React.useMemo(\n () => ({\n disabled,\n readOnly,\n setValue,\n value,\n }),\n [disabled, readOnly, value]\n );\n\n return (\n <Listbox2Context.Provider value={context}>\n <div data-taco=\"listbox2\">\n <CollectionPrimitive.Root\n {...otherProps}\n aria-multiselectable={multiple ? true : undefined}\n id={id}\n ref={ref}\n role=\"listbox\"\n querySelector={customSelector ? `${DEFAULT_SELECTOR}, ${customSelector}` : DEFAULT_SELECTOR}>\n {children}\n </CollectionPrimitive.Root>\n </div>\n </Listbox2Context.Provider>\n );\n});\n\nexport const createListboxValueSetter =\n (multiple: boolean, setValue: React.Dispatch<React.SetStateAction<Listbox2Value | undefined>>) =>\n (nextValue: Listbox2Value) => {\n setValue(value => {\n if (Array.isArray(nextValue)) {\n return nextValue;\n }\n\n if (multiple) {\n if (value === undefined) {\n return [nextValue];\n } else if (Array.isArray(value)) {\n if (value.includes(nextValue)) {\n return value.filter(v => v !== nextValue);\n }\n\n return [...value, nextValue];\n } else if (value === nextValue) {\n return [];\n }\n\n return [value, nextValue];\n }\n\n return nextValue;\n });\n };\n"],"names":["DEFAULT_SELECTOR","Root","React","forwardRef","Listbox2","props","ref","children","customSelector","disabled","id","nativeId","multiple","readOnly","setValue","title","value","otherProps","useId","context","useMemo","Listbox2Context","Provider","CollectionPrimitive","undefined","role","querySelector","createListboxValueSetter","nextValue","Array","isArray","includes","filter","v"],"mappings":";;;;;AAeA,MAAMA,gBAAgB,GAAG,iBAAiB;MAE7BC,IAAI,gBAAGC,cAAK,CAACC,UAAU,CAAmD,SAASC,QAAQ,CAACC,KAAK,EAAEC,GAAG;EAC/G,MAAM;IACFC,QAAQ;IACRC,cAAc;IACdC,QAAQ,GAAG,KAAK;IAChBC,EAAE,EAAEC,QAAQ;IACZC,QAAQ;IACRC,QAAQ,GAAG,KAAK;IAChBC,QAAQ;IACRC,KAAK;IACLC,KAAK;IACL,GAAGC;GACN,GAAGZ,KAAK;EACT,MAAMK,EAAE,GAAGQ,KAAK,CAACP,QAAQ,CAAC;EAE1B,MAAMQ,OAAO,GAAGjB,cAAK,CAACkB,OAAO,CACzB,OAAO;IACHX,QAAQ;IACRI,QAAQ;IACRC,QAAQ;IACRE;GACH,CAAC,EACF,CAACP,QAAQ,EAAEI,QAAQ,EAAEG,KAAK,CAAC,CAC9B;EAED,oBACId,6BAACmB,eAAe,CAACC,QAAQ;IAACN,KAAK,EAAEG;kBAC7BjB;iBAAe;kBACXA,6BAACqB,MAAwB,oBACjBN,UAAU;4BACQL,QAAQ,GAAG,IAAI,GAAGY,SAAS;IACjDd,EAAE,EAAEA,EAAE;IACNJ,GAAG,EAAEA,GAAG;IACRmB,IAAI,EAAC,SAAS;IACdC,aAAa,EAAElB,cAAc,MAAMR,qBAAqBQ,gBAAgB,GAAGR;MAC1EO,QAAQ,CACc,CACzB,CACiB;AAEnC,CAAC;MAEYoB,wBAAwB,GACjC,CAACf,QAAiB,EAAEE,QAAyE,KAC5Fc,SAAwB;EACrBd,QAAQ,CAACE,KAAK;IACV,IAAIa,KAAK,CAACC,OAAO,CAACF,SAAS,CAAC,EAAE;MAC1B,OAAOA,SAAS;;IAGpB,IAAIhB,QAAQ,EAAE;MACV,IAAII,KAAK,KAAKQ,SAAS,EAAE;QACrB,OAAO,CAACI,SAAS,CAAC;OACrB,MAAM,IAAIC,KAAK,CAACC,OAAO,CAACd,KAAK,CAAC,EAAE;QAC7B,IAAIA,KAAK,CAACe,QAAQ,CAACH,SAAS,CAAC,EAAE;UAC3B,OAAOZ,KAAK,CAACgB,MAAM,CAACC,CAAC,IAAIA,CAAC,KAAKL,SAAS,CAAC;;QAG7C,OAAO,CAAC,GAAGZ,KAAK,EAAEY,SAAS,CAAC;OAC/B,MAAM,IAAIZ,KAAK,KAAKY,SAAS,EAAE;QAC5B,OAAO,EAAE;;MAGb,OAAO,CAACZ,KAAK,EAAEY,SAAS,CAAC;;IAG7B,OAAOA,SAAS;GACnB,CAAC;AACN;;;;"}
@@ -1,12 +1,12 @@
1
1
  import React from 'react';
2
2
  export declare type CollectionProps = React.HTMLAttributes<HTMLDivElement> & {
3
- selector: string;
3
+ querySelector: string;
4
4
  };
5
5
  export declare type CollectionRef = HTMLDivElement & {
6
6
  setActiveIndex: (option: HTMLDivElement) => void;
7
7
  };
8
8
  export declare const Root: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & {
9
- selector: string;
9
+ querySelector: string;
10
10
  } & React.RefAttributes<CollectionRef>>;
11
11
  export declare const getNextIndexFromKeycode: (event: React.KeyboardEvent, length: number, activeIndex: number | undefined) => number | undefined;
12
12
  export declare const getNextEnabledItem: (event: React.KeyboardEvent<HTMLElement>, options: NodeListOf<Element>, activeIndex: number | undefined, recurse?: boolean) => number | undefined;
@@ -7288,98 +7288,87 @@ const isAriaDirectionKey = event => {
7288
7288
  return false;
7289
7289
  };
7290
7290
 
7291
- const getOptions = (collection, selector) => collection.querySelectorAll(selector);
7291
+ const getOptionsFromCollection = (collection, selector) => collection.querySelectorAll(selector);
7292
7292
  // we use javascript to set attributes (rather than cloning children and adding them)
7293
7293
  // so that we can support nesting (e.g. groups) - child elements that aren't options.
7294
7294
  // without doing this we would have to unwrap and flatten all groups
7295
7295
  const Root = /*#__PURE__*/React__default.forwardRef(function CollectionRoot(props, ref) {
7296
7296
  const {
7297
- selector,
7297
+ querySelector,
7298
7298
  tabIndex = 0,
7299
7299
  ...otherProps
7300
7300
  } = props;
7301
7301
  const internalRef = useMergedRef(ref);
7302
7302
  const [activeIndex, setActiveIndex] = React__default.useState();
7303
- const toggleCurrent = collection => {
7303
+ const lastLengthRef = React__default.useRef(0);
7304
+ const setActiveOption = (index, collection, option) => {
7304
7305
  var _collection$querySele;
7305
7306
  (_collection$querySele = collection.querySelector(`[aria-current]`)) === null || _collection$querySele === void 0 ? void 0 : _collection$querySele.removeAttribute('aria-current');
7306
- if (activeIndex !== undefined) {
7307
- var _getOptions;
7308
- const option = (_getOptions = getOptions(collection, selector)) === null || _getOptions === void 0 ? void 0 : _getOptions.item(activeIndex);
7309
- if (option) {
7310
- option.setAttribute('aria-current', 'true');
7311
- option.scrollIntoView({
7312
- block: 'nearest'
7313
- });
7314
- }
7315
- }
7307
+ option.setAttribute('aria-current', 'true');
7308
+ option.scrollIntoView({
7309
+ block: 'nearest'
7310
+ });
7311
+ setActiveIndex(index);
7316
7312
  };
7317
7313
  const setActiveIndexByElement = React__default.useCallback(option => {
7318
7314
  if (internalRef.current) {
7319
- if (option.matches(selector)) {
7320
- const options = getOptions(internalRef.current, selector);
7315
+ if (option.matches(querySelector)) {
7316
+ const options = getOptionsFromCollection(internalRef.current, querySelector);
7321
7317
  const nextActiveIndex = Array.from(options).indexOf(option);
7322
7318
  if (nextActiveIndex > -1) {
7323
- setActiveIndex(nextActiveIndex);
7319
+ setActiveOption(nextActiveIndex, internalRef.current, option);
7324
7320
  }
7325
7321
  }
7326
7322
  }
7327
- }, [internalRef.current]);
7323
+ }, [internalRef.current, querySelector]);
7328
7324
  React__default.useEffect(() => {
7329
7325
  if (internalRef.current) {
7330
7326
  internalRef.current.setActiveIndex = setActiveIndexByElement;
7331
7327
  }
7332
7328
  }, [internalRef.current]);
7333
- // set/remove appropriate aria-current attributes
7334
- // we do this in a hook because we expose setActiveIndex on the ref
7335
7329
  React__default.useEffect(() => {
7336
7330
  if (internalRef.current) {
7337
- toggleCurrent(internalRef.current);
7338
- }
7339
- }, [activeIndex]);
7340
- // set the initial active index on mount
7341
- React__default.useEffect(() => {
7342
- if (internalRef.current) {
7343
- const selected = internalRef.current.querySelectorAll(`[aria-selected]`);
7344
- if (selected.length === 1) {
7345
- const options = getOptions(internalRef.current, selector);
7346
- if (options) {
7347
- const selectedIndex = Array.from(options).indexOf(selected.item(0));
7348
- if (selectedIndex > -1) {
7349
- setActiveIndex(selectedIndex);
7331
+ const options = getOptionsFromCollection(internalRef.current, querySelector);
7332
+ if (options.length && options.length !== lastLengthRef.current) {
7333
+ const selected = internalRef.current.querySelectorAll(`[aria-selected]`);
7334
+ if (selected.length === 1) {
7335
+ if (options) {
7336
+ const firstSelected = selected.item(0);
7337
+ const selectedIndex = Array.from(options).indexOf(firstSelected);
7338
+ if (selectedIndex > -1) {
7339
+ setActiveOption(selectedIndex, internalRef.current, firstSelected);
7340
+ }
7350
7341
  }
7342
+ } else {
7343
+ // multiple selected or none selected should go to 0
7344
+ setActiveOption(0, internalRef.current, options.item(0));
7351
7345
  }
7352
- } else {
7353
- // multiple selected or none selected should go to 0
7354
- setActiveIndex(0);
7355
- }
7356
- }
7357
- }, []);
7358
- // if children length changes, make sure we still have a valid active index (e.g. searching/filtering or adding a new item)
7359
- React__default.useEffect(() => {
7360
- if (internalRef.current) {
7361
- // make sure index and dom are synced
7362
- toggleCurrent(internalRef.current);
7363
- if (activeIndex !== undefined && activeIndex > React__default.Children.count(props.children)) {
7364
- setActiveIndex(0);
7365
7346
  }
7347
+ lastLengthRef.current = options.length;
7366
7348
  }
7367
7349
  }, [props.children]);
7368
7350
  const handleClick = event => {
7369
- setActiveIndexByElement(event.target);
7351
+ const option = event.target;
7352
+ if (option.matches(querySelector)) {
7353
+ const options = getOptionsFromCollection(event.currentTarget, querySelector);
7354
+ const nextActiveIndex = Array.from(options).indexOf(option);
7355
+ if (nextActiveIndex > -1) {
7356
+ setActiveOption(nextActiveIndex, event.currentTarget, option);
7357
+ }
7358
+ }
7370
7359
  };
7371
7360
  const handleKeyDown = event => {
7372
7361
  // this stops the event dispatched to the option rebounding back and starting an infinite loop
7373
7362
  if (event.target !== event.currentTarget) {
7374
7363
  return;
7375
7364
  }
7376
- const options = getOptions(event.currentTarget, selector);
7365
+ const options = getOptionsFromCollection(event.currentTarget, querySelector);
7377
7366
  if (options) {
7378
7367
  if (isAriaDirectionKey(event)) {
7379
7368
  const nextActiveIndex = getNextEnabledItem$1(event, options, activeIndex);
7380
7369
  if (nextActiveIndex !== undefined && nextActiveIndex !== activeIndex) {
7381
7370
  event.preventDefault();
7382
- setActiveIndex(nextActiveIndex);
7371
+ setActiveOption(nextActiveIndex, event.currentTarget, options.item(nextActiveIndex));
7383
7372
  }
7384
7373
  } else if (activeIndex !== undefined) {
7385
7374
  // forward events onto the underlying option - this lets consumers place onKeyDown handlers on their own components
@@ -7391,7 +7380,7 @@ const Root = /*#__PURE__*/React__default.forwardRef(function CollectionRoot(prop
7391
7380
  onClick: handleClick,
7392
7381
  onKeyDown: handleKeyDown,
7393
7382
  ref: internalRef,
7394
- tabIndex: tabIndex !== null && tabIndex !== void 0 ? tabIndex : 0
7383
+ tabIndex: tabIndex
7395
7384
  }));
7396
7385
  });
7397
7386
  const getNextIndexFromKeycode = (event, length, activeIndex) => {
@@ -7471,7 +7460,7 @@ const Root$1 = /*#__PURE__*/React__default.forwardRef(function Listbox2(props, r
7471
7460
  id: id,
7472
7461
  ref: ref,
7473
7462
  role: "listbox",
7474
- selector: customSelector ? `${DEFAULT_SELECTOR}, ${customSelector}` : DEFAULT_SELECTOR
7463
+ querySelector: customSelector ? `${DEFAULT_SELECTOR}, ${customSelector}` : DEFAULT_SELECTOR
7475
7464
  }), children)));
7476
7465
  });
7477
7466
  const createListboxValueSetter = (multiple, setValue) => nextValue => {
@@ -8040,9 +8029,7 @@ const Single = /*#__PURE__*/React__default.forwardRef(function Select2TriggerSin
8040
8029
  readOnly,
8041
8030
  tags
8042
8031
  } = useSelect2Context();
8043
- const contentClassName = cn('truncate', {
8044
- 'flex gap-1': tags
8045
- });
8032
+ const contentClassName = cn('truncate flex items-center gap-1');
8046
8033
  const currentValue = children.find(matchesValue(value));
8047
8034
  let output;
8048
8035
  if (currentValue) {
@@ -8056,7 +8043,6 @@ const Single = /*#__PURE__*/React__default.forwardRef(function Select2TriggerSin
8056
8043
  }, currentValue.props.children);
8057
8044
  } else {
8058
8045
  output = /*#__PURE__*/React__default.createElement(React__default.Fragment, null, currentValue.props.icon ? typeof currentValue.props.icon === 'string' ? /*#__PURE__*/React__default.createElement(Icon, {
8059
- className: "mr-1",
8060
8046
  name: currentValue.props.icon
8061
8047
  }) : currentValue.props.icon : null, currentValue.props.children);
8062
8048
  }