@rescui/select 0.15.1-RUI-280-Update-select-component-downshift-cd2a98813.66 → 0.15.1-RUI-280-Update-select-component-downshift-2f40ef205.67

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.
@@ -3,7 +3,6 @@ import cn from 'classnames';
3
3
  import { Dropdown } from '@rescui/dropdown';
4
4
  import { useSelect } from 'downshift';
5
5
  import { useThemeWithUndefined } from '@rescui/ui-contexts';
6
- import { useFocusRing } from '@react-aria/focus';
7
6
  import scrollIntoView from 'scroll-into-view-if-needed';
8
7
  import { useLabelFocus } from './hooks/use-label-focus.js';
9
8
  import { useOptions } from './hooks/use-options.js';
@@ -212,14 +211,7 @@ function Multiselect(_ref) {
212
211
  if (dropdownRef.current) {
213
212
  dropdownRef.current.scheduleUpdate();
214
213
  }
215
- }, [selectedItems]); // use it instead of ":has(:focus-visible), :focus-visible"
216
-
217
- const {
218
- isFocusVisible,
219
- focusProps
220
- } = useFocusRing({
221
- within: true
222
- });
214
+ }, [selectedItems]);
223
215
  const {
224
216
  isFocusedByLabel,
225
217
  labelClickProps,
@@ -273,14 +265,17 @@ function Multiselect(_ref) {
273
265
  let {
274
266
  ref: triggerRefForDropdown
275
267
  } = _ref3;
276
- return /*#__PURE__*/React.createElement("div", { ...rest,
268
+ return /*#__PURE__*/React.createElement("div", {
269
+ className: styles.triggerContainer,
270
+ "data-open": isOpen,
271
+ "data-label-focused": isFocusedByLabel
272
+ }, /*#__PURE__*/React.createElement("div", { ...rest,
277
273
  ...mergeProps(fieldProps, // aria-invalid & aria-describedby, rest are overridden by triggerProps
278
- triggerProps, focusProps, labelFocusForTriggerProps, {
274
+ triggerProps, labelFocusForTriggerProps, {
279
275
  ref: triggerRefForDropdown
280
276
  }),
281
277
  className: cn(styles.trigger, !isSingleLine && styles.canBeMultiline),
282
278
  "data-open": isOpen,
283
- "data-has-focus-visible": isFocusVisible,
284
279
  "data-label-focused": isFocusedByLabel,
285
280
  "data-test": "multiselect__trigger"
286
281
  }, /*#__PURE__*/React.createElement(MultiTrigger, {
@@ -303,7 +298,7 @@ function Multiselect(_ref) {
303
298
  });
304
299
  },
305
300
  triggerId: triggerProps.id
306
- }));
301
+ })));
307
302
  }
308
303
  }, /*#__PURE__*/React.createElement(ListBox, {
309
304
  state: listBoxState,
@@ -4,16 +4,17 @@ import PropTypes from 'prop-types';
4
4
  import cn from 'classnames';
5
5
  import { useThemeWithUndefined } from '@rescui/ui-contexts';
6
6
  import { ErrorMessage } from '@rescui/form-field';
7
- import { useFocus, useHover } from 'react-aria';
8
7
  import { nativeOptionType, nativeOptionsGroupType, noOptionsMessageType } from './common-prop-types.js';
9
8
  import { useA11y } from './hooks/use-a11y.js';
9
+ import { useHover } from './hooks/use-hover.js';
10
+ import { useFocus } from './hooks/use-focus.js';
10
11
  import { FormTriggerWrapper } from './parts/form-trigger-wrapper.js';
11
- import { NativeSelectTrigger } from './parts/native-select-trigger.js';
12
12
  import { NativeSelectOptionsWithGroups } from './parts/native-select-options-with-groups.js';
13
+ import { Icons } from './parts/icons.js';
13
14
  import { isOptionAGroup } from './utils/is-option-a-group.js';
14
15
  import { getEmptyMessage } from './utils/get-empty-message.js';
15
16
  import { mergeProps } from './utils/merge-props.js';
16
- import styles from './styles/native-select.p.module.css.js';
17
+ import styles from './styles/common.p.module.css.js';
17
18
 
18
19
  function findSelectedOption(options, selectedValue) {
19
20
  let result = null;
@@ -41,6 +42,10 @@ const SIZE_STYLES = {
41
42
  s: styles.sizeS,
42
43
  m: styles.sizeM,
43
44
  l: styles.sizeL
45
+ };
46
+ const THEME_STYLES = {
47
+ light: styles.themeLight,
48
+ dark: styles.themeDark
44
49
  }; // eslint-disable-next-line complexity
45
50
 
46
51
  const NativeSelect = _ref => {
@@ -96,12 +101,11 @@ const NativeSelect = _ref => {
96
101
  // replace it with ":focus + &" selector in that case
97
102
 
98
103
 
99
- const [isFocused, setIsFocused] = React.useState(false);
100
104
  const {
105
+ isFocused,
101
106
  focusProps
102
107
  } = useFocus({
103
- isDisabled,
104
- onFocusChange: setIsFocused
108
+ isDisabled
105
109
  }); // same as above, could be replaced with ":hover + &" selector
106
110
 
107
111
  const {
@@ -116,7 +120,7 @@ const NativeSelect = _ref => {
116
120
  noOptionsMessage
117
121
  });
118
122
  return /*#__PURE__*/React.createElement("div", {
119
- className: cn(className, styles.main, SIZE_STYLES[size]),
123
+ className: cn(className, styles.root, SIZE_STYLES[size], THEME_STYLES[theme], styles.classic, isDisabled ? styles.disabled : styles.enabled, Boolean(error) && styles.error),
120
124
  id: id,
121
125
  style: style,
122
126
  "data-test": "native-select"
@@ -133,7 +137,7 @@ const NativeSelect = _ref => {
133
137
  note: note,
134
138
  descriptionProps: descriptionProps
135
139
  }, /*#__PURE__*/React.createElement("div", {
136
- className: styles.wrapper
140
+ className: styles.triggerContainer
137
141
  }, /*#__PURE__*/React.createElement("select", { ...rest,
138
142
  ...mergeProps(fieldProps, focusProps, hoverProps, {
139
143
  onKeyDown: event => {
@@ -161,11 +165,16 @@ const NativeSelect = _ref => {
161
165
  selectedLabel: value === null || value === void 0 ? void 0 : value.label,
162
166
  selectedValue: value === null || value === void 0 ? void 0 : value.value,
163
167
  placeholder
164
- }) : /*#__PURE__*/React.createElement(NativeSelectTrigger, {
165
- value: value,
168
+ }) : /*#__PURE__*/React.createElement("div", {
169
+ className: cn(styles.trigger),
170
+ "data-test": 'native-select_trigger',
171
+ "data-rs-internal": 'select-native-trigger'
172
+ }, /*#__PURE__*/React.createElement("span", {
173
+ className: cn(styles.triggerText, !(value !== null && value !== void 0 && value.value) && styles.labelNotSelected),
174
+ "data-test": 'native-select_trigger_text',
175
+ "aria-hidden": "true"
176
+ }, (value === null || value === void 0 ? void 0 : value.label) ?? placeholder), /*#__PURE__*/React.createElement(Icons, {
166
177
  isLoading: isLoading,
167
- isDisabled: isDisabled,
168
- isClearable: isClearable,
169
178
  triggerId: fieldProps.id,
170
179
  onClear: () => {
171
180
  var _triggerRef$current;
@@ -175,11 +184,8 @@ const NativeSelect = _ref => {
175
184
  focusVisible: false
176
185
  });
177
186
  },
178
- size: size,
179
- theme: theme,
180
- hasError: Boolean(error),
181
- placeholder: placeholder
182
- }))));
187
+ canHaveClearIcon: isClearable && !isDisabled && Boolean(value === null || value === void 0 ? void 0 : value.value)
188
+ })))));
183
189
  };
184
190
 
185
191
  NativeSelect.propTypes = {
@@ -31,7 +31,7 @@ const HiddenSelect = _ref => {
31
31
  const allItems = Array.from( // map will deduplicate options by values
32
32
  new Map((!value ? options : [...options, ...arrayValue]).map(item => [item.value, item])).values());
33
33
  return /*#__PURE__*/React.createElement("div", {
34
- className: styles.hiddenSelect
34
+ className: styles.visuallyHidden
35
35
  }, /*#__PURE__*/React.createElement("select", { ...selectProps
36
36
  }, /*#__PURE__*/React.createElement("option", {
37
37
  value: "",
@@ -5,7 +5,6 @@ declare type ClearOrLoadingProps = {
5
5
  onClearClick: () => void;
6
6
  triggerId?: string;
7
7
  className?: string;
8
- customStylesMap?: Record<string, string>;
9
8
  };
10
9
  export declare const ClearOrLoading: React.FC<ClearOrLoadingProps>;
11
10
  export declare type IconsProps = {
@@ -13,7 +12,6 @@ export declare type IconsProps = {
13
12
  canHaveClearIcon?: boolean;
14
13
  onClear?: () => void;
15
14
  triggerId?: string;
16
- customStylesMap?: Record<string, string>;
17
15
  };
18
- export declare const Icons: ({ isLoading, canHaveClearIcon, onClear, triggerId, customStylesMap: styles }: IconsProps) => JSX.Element;
16
+ export declare const Icons: ({ isLoading, canHaveClearIcon, onClear, triggerId }: IconsProps) => JSX.Element;
19
17
  export {};
@@ -11,8 +11,7 @@ const ClearOrLoading = _ref => {
11
11
  canHaveClearIcon,
12
12
  onClearClick,
13
13
  triggerId,
14
- className,
15
- customStylesMap: styles$1 = styles
14
+ className
16
15
  } = _ref;
17
16
 
18
17
  if (isLoading) {
@@ -20,14 +19,14 @@ const ClearOrLoading = _ref => {
20
19
  style: {
21
20
  pointerEvents: 'none'
22
21
  },
23
- className: cn(className, styles$1.icon),
22
+ className: cn(className, styles.icon),
24
23
  "data-test": "loading-icon",
25
24
  "data-render-all-sizes": true
26
25
  });
27
26
  } else if (canHaveClearIcon) {
28
27
  return /*#__PURE__*/React.createElement("button", {
29
28
  type: "button",
30
- className: cn(className, styles$1.icon, styles$1.clearIcon),
29
+ className: cn(className, styles.icon, styles.clearIcon),
31
30
  "data-test": "clear-icon",
32
31
  onClick: e => {
33
32
  e.stopPropagation();
@@ -51,19 +50,17 @@ const Icons = _ref2 => {
51
50
  isLoading,
52
51
  canHaveClearIcon,
53
52
  onClear,
54
- triggerId,
55
- customStylesMap: styles$1 = styles
53
+ triggerId
56
54
  } = _ref2;
57
55
  return /*#__PURE__*/React.createElement("div", {
58
- className: styles$1.iconsWrapper
56
+ className: styles.iconsWrapper
59
57
  }, /*#__PURE__*/React.createElement(ClearOrLoading, {
60
58
  isLoading: isLoading,
61
59
  canHaveClearIcon: canHaveClearIcon,
62
60
  onClearClick: onClear,
63
- triggerId: triggerId,
64
- customStylesMap: styles$1
61
+ triggerId: triggerId
65
62
  }), /*#__PURE__*/React.createElement(DownOutlineIcon, {
66
- className: styles$1.toggle,
63
+ className: styles.toggle,
67
64
  "data-test": "toggle-icon",
68
65
  "data-render-all-sizes": true
69
66
  }));