@v-c/select 1.2.0 → 1.2.2

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.
@@ -1,7 +1,7 @@
1
1
  import { AlignType, BuildInPlacements } from '@v-c/trigger';
2
2
  import { VueNode } from '@v-c/util/dist/type';
3
3
  import { ScrollConfig, ScrollTo } from '@v-c/virtual-list';
4
- import { CSSProperties } from 'vue';
4
+ import { CSSProperties, StyleValue } from 'vue';
5
5
  import { ComponentsConfig } from '../hooks';
6
6
  import { DisplayInfoType, DisplayValueType, Mode, Placement, RawValueType, RenderDOMFunc, RenderNode } from '../interface';
7
7
  export type BaseSelectSemanticName = 'prefix' | 'suffix' | 'input' | 'clear' | 'placeholder' | 'content' | 'item' | 'itemContent' | 'itemRemove';
@@ -62,7 +62,7 @@ export interface BaseSelectPrivateProps {
62
62
  export type BaseSelectPropsWithoutPrivate = Omit<BaseSelectProps, keyof BaseSelectPrivateProps>;
63
63
  export interface BaseSelectProps extends BaseSelectPrivateProps {
64
64
  className?: string;
65
- style?: CSSProperties;
65
+ style?: StyleValue;
66
66
  classNames?: Partial<Record<BaseSelectSemanticName, string>>;
67
67
  styles?: Partial<Record<BaseSelectSemanticName, CSSProperties>>;
68
68
  showSearch?: boolean;
@@ -390,7 +390,13 @@ var BaseSelect = /* @__PURE__ */ defineComponent((props, { expose, attrs }) => {
390
390
  default: void 0
391
391
  },
392
392
  style: {
393
- type: Object,
393
+ type: [
394
+ Boolean,
395
+ null,
396
+ String,
397
+ Object,
398
+ Array
399
+ ],
394
400
  required: false,
395
401
  default: void 0
396
402
  },
@@ -145,6 +145,23 @@ var OptionList = /* @__PURE__ */ defineComponent({
145
145
  }
146
146
  };
147
147
  const onKeyUp = () => {};
148
+ const optionPositionInfo = computed(() => {
149
+ let count = 0;
150
+ let group = null;
151
+ const positions = [];
152
+ const groups = [];
153
+ memoFlattenOptions.value.forEach((item) => {
154
+ if (item.group) {
155
+ group = item;
156
+ positions.push(count);
157
+ groups.push(null);
158
+ } else {
159
+ positions.push(count += 1);
160
+ groups.push(item.groupOption ? group : null);
161
+ }
162
+ });
163
+ return [positions, groups];
164
+ });
148
165
  expose({
149
166
  onKeyDown,
150
167
  onKeyUp,
@@ -170,18 +187,49 @@ var OptionList = /* @__PURE__ */ defineComponent({
170
187
  id: `${id}_list_${index}`
171
188
  };
172
189
  }
190
+ const [optionPositions, itemGroups] = optionPositionInfo.value;
173
191
  const renderItem = (index) => {
174
192
  const item = memoFlattenOptions.value[index];
175
193
  if (!item) return null;
176
194
  const itemData = item.data || {};
177
195
  const { value, disabled } = itemData;
178
- const { group } = item;
179
196
  const attrs = pickAttrs(itemData, true);
180
197
  const mergedLabel = getLabel(item);
181
- return item ? createVNode("div", mergeProps({ "aria-label": typeof mergedLabel === "string" && !group ? mergedLabel : void 0 }, attrs, { "key": index }, getItemAriaProps(item, index), {
198
+ return createVNode("div", mergeProps({
199
+ "aria-label": isTitleType(mergedLabel) ? String(mergedLabel) : void 0,
200
+ "aria-setsize": optionPositions[optionPositions.length - 1] ?? 0,
201
+ "aria-posinset": optionPositions[index]
202
+ }, attrs, { "key": index }, getItemAriaProps(item, index), {
182
203
  "aria-selected": isAriaSelected(value),
183
204
  "aria-disabled": disabled
184
- }), [value]) : null;
205
+ }), [value]);
206
+ };
207
+ const renderHiddenItems = () => {
208
+ const segments = [];
209
+ [
210
+ activeIndex.value - 1,
211
+ activeIndex.value,
212
+ activeIndex.value + 1
213
+ ].forEach((index) => {
214
+ const item = memoFlattenOptions.value[index];
215
+ if (!item || item.group) return;
216
+ const groupItem = itemGroups[index];
217
+ const lastSegment = segments[segments.length - 1];
218
+ if (lastSegment && lastSegment.group === groupItem) lastSegment.indexes.push(index);
219
+ else segments.push({
220
+ group: groupItem,
221
+ indexes: [index]
222
+ });
223
+ });
224
+ return segments.map(({ group, indexes }) => {
225
+ if (!group) return indexes.map(renderItem);
226
+ const groupLabel = getLabel(group);
227
+ return createVNode("div", {
228
+ "key": group.key,
229
+ "role": "group",
230
+ "aria-label": group.data.title ?? (isTitleType(groupLabel) ? String(groupLabel) : void 0)
231
+ }, [indexes.map(renderItem)]);
232
+ });
185
233
  };
186
234
  const a11yProps = {
187
235
  role: "listbox",
@@ -191,11 +239,7 @@ var OptionList = /* @__PURE__ */ defineComponent({
191
239
  height: 0,
192
240
  width: 0,
193
241
  overflow: "hidden"
194
- } }), [
195
- renderItem(activeIndex.value - 1),
196
- renderItem(activeIndex.value),
197
- renderItem(activeIndex.value + 1)
198
- ]), createVNode(List, mergeProps({
242
+ } }), [renderHiddenItems()]), createVNode(List, mergeProps({
199
243
  "prefixCls": `${baseProps.value?.prefixCls}-dropdown-list`,
200
244
  "itemKey": "key",
201
245
  "ref": (el) => {
package/dist/Select.js CHANGED
@@ -228,7 +228,13 @@ var Select = /* @__PURE__ */ defineComponent({
228
228
  default: void 0
229
229
  },
230
230
  style: {
231
- type: Object,
231
+ type: [
232
+ Boolean,
233
+ null,
234
+ String,
235
+ Object,
236
+ Array
237
+ ],
232
238
  required: false,
233
239
  default: void 0
234
240
  },
@@ -1,5 +1,5 @@
1
1
  import { VueNode } from '@v-c/util/dist/type';
2
- import { CSSProperties } from 'vue';
2
+ import { StyleValue } from 'vue';
3
3
  import { ComponentsConfig } from '../hooks';
4
4
  import { DisplayValueType, Mode, RenderNode } from '../interface';
5
5
  export interface SelectInputRef {
@@ -32,7 +32,7 @@ export interface SelectInputProps {
32
32
  /** Check if `tokenSeparators` contains `\n` or `\r\n` */
33
33
  tokenWithEnter?: boolean;
34
34
  className?: string;
35
- style?: CSSProperties;
35
+ style?: StyleValue;
36
36
  focused?: boolean;
37
37
  components: ComponentsConfig;
38
38
  onFocus?: (event: FocusEvent) => void;
@@ -5,7 +5,7 @@ import { useSelectInputProvider } from "./context.js";
5
5
  import SelectContent from "./Content/index.js";
6
6
  import { cloneVNode, computed, createVNode, defineComponent, isVNode, mergeProps, shallowRef } from "vue";
7
7
  import { clsx } from "@v-c/util";
8
- import KeyCode from "@v-c/util/dist/KeyCode";
8
+ import KeyCode, { KeyCodeStr } from "@v-c/util/dist/KeyCode";
9
9
  import omit from "@v-c/util/dist/omit";
10
10
  import { getDOM } from "@v-c/util/dist/Dom/findDOMNode";
11
11
  //#region src/SelectInput/index.tsx
@@ -102,6 +102,9 @@ var SelectInput = /* @__PURE__ */ defineComponent((props, { attrs, expose, slots
102
102
  }
103
103
  props?.onMouseDown?.(event);
104
104
  };
105
+ const onClearKeydown = (event) => {
106
+ if (event.key === KeyCodeStr.Enter || event.key === KeyCodeStr.Space) event.stopPropagation();
107
+ };
105
108
  useSelectInputProvider(computed(() => ({
106
109
  ...props,
107
110
  onInputKeyDown: onInternalInputKeyDown
@@ -162,6 +165,7 @@ var SelectInput = /* @__PURE__ */ defineComponent((props, { attrs, expose, slots
162
165
  e.preventDefault();
163
166
  e._select_lazy = true;
164
167
  },
168
+ "onKeydown": onClearKeydown,
165
169
  "onClick": (e) => onClearMouseDown.value?.(e)
166
170
  }, [clearIcon.value]),
167
171
  slots.default?.()
@@ -323,7 +327,13 @@ var SelectInput = /* @__PURE__ */ defineComponent((props, { attrs, expose, slots
323
327
  default: void 0
324
328
  },
325
329
  style: {
326
- type: Object,
330
+ type: [
331
+ Boolean,
332
+ null,
333
+ String,
334
+ Object,
335
+ Array
336
+ ],
327
337
  required: false,
328
338
  default: void 0
329
339
  },
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@v-c/select",
3
3
  "type": "module",
4
- "version": "1.2.0",
4
+ "version": "1.2.2",
5
5
  "description": "",
6
6
  "author": "",
7
7
  "license": "MIT",
@@ -34,10 +34,10 @@
34
34
  "vue": "^3.0.0"
35
35
  },
36
36
  "dependencies": {
37
+ "@v-c/overflow": "^1.1.1",
37
38
  "@v-c/trigger": "^1.1.0",
38
- "@v-c/virtual-list": "^1.1.0",
39
- "@v-c/util": "^1.1.0",
40
- "@v-c/overflow": "^1.1.1"
39
+ "@v-c/virtual-list": "^1.1.1",
40
+ "@v-c/util": "^1.1.0"
41
41
  },
42
42
  "scripts": {
43
43
  "build": "vite build",