@antify/ui 2.4.2 → 2.4.4
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/components/inputs/Elements/AntSelectMenu.vue +76 -15
- package/dist/components/inputs/__stories/AntSelect.stories.d.ts +1 -0
- package/dist/components/inputs/__stories/AntSelect.stories.js +40 -1
- package/dist/components/inputs/__stories/AntSelect.stories.mjs +46 -0
- package/dist/components/inputs/__types/AntSelect.types.d.ts +2 -1
- package/package.json +1 -1
|
@@ -121,7 +121,7 @@ watch(isOpen, () => {
|
|
|
121
121
|
focusedDropDownItem.value =
|
|
122
122
|
typeof _modelValue.value === 'string' || typeof _modelValue.value === 'number' ? _modelValue.value :
|
|
123
123
|
Array.isArray(_modelValue.value) ? _modelValue.value[0] :
|
|
124
|
-
props.options[0].value;
|
|
124
|
+
(props.options[0].value || null);
|
|
125
125
|
} else {
|
|
126
126
|
focusedDropDownItem.value = null;
|
|
127
127
|
}
|
|
@@ -138,6 +138,56 @@ onUnmounted(() => {
|
|
|
138
138
|
reference.value?.removeEventListener('keydown', onKeyDownDropDown);
|
|
139
139
|
});
|
|
140
140
|
|
|
141
|
+
/**
|
|
142
|
+
* Get the next focusable select option.
|
|
143
|
+
* It skips group labels and goes to beginning of the list if it reaches the end.
|
|
144
|
+
*
|
|
145
|
+
* @param currentOptionIndex
|
|
146
|
+
*/
|
|
147
|
+
function getNextFocusableSelectOption(currentOptionIndex: number): number | null {
|
|
148
|
+
for (let i = currentOptionIndex + 1; i < props.options.length; i++) {
|
|
149
|
+
if (!props.options[i].isGroupLabel) {
|
|
150
|
+
return i;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// If no next option is found, return the first option, but make sure
|
|
155
|
+
// to skip group labels again.
|
|
156
|
+
for (let i = 0; i < props.options.length; i++) {
|
|
157
|
+
if (!props.options[i].isGroupLabel) {
|
|
158
|
+
return i;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Seems that the option list is empty or all options are group labels.
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Get the prev focusable select option.
|
|
168
|
+
* It skips group labels and goes to end of the list if it reaches the end.
|
|
169
|
+
*
|
|
170
|
+
* @param currentOptionIndex
|
|
171
|
+
*/
|
|
172
|
+
function getPrevFocusableSelectOption(currentOptionIndex: number): number | null {
|
|
173
|
+
for (let i = currentOptionIndex - 1; i >= 0; i--) {
|
|
174
|
+
if (!props.options[i].isGroupLabel) {
|
|
175
|
+
return i;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// If no previous option is found, return the last option, but make sure
|
|
180
|
+
// to skip group labels again.
|
|
181
|
+
for (let i = props.options.length - 1; i >= 0; i--) {
|
|
182
|
+
if (!props.options[i].isGroupLabel) {
|
|
183
|
+
return i;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Seems that the option list is empty or all options are group labels.
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
|
|
141
191
|
function onKeyDownDropDown(e: KeyboardEvent) {
|
|
142
192
|
if (e.key === 'Enter') {
|
|
143
193
|
if (props.closeOnEnter) {
|
|
@@ -160,12 +210,10 @@ function onKeyDownDropDown(e: KeyboardEvent) {
|
|
|
160
210
|
isOpen.value = true;
|
|
161
211
|
|
|
162
212
|
const index = props.options.findIndex(option => option.value === focusedDropDownItem.value);
|
|
163
|
-
const
|
|
213
|
+
const nextOptionIndex = getNextFocusableSelectOption(index);
|
|
164
214
|
|
|
165
|
-
if (
|
|
166
|
-
focusedDropDownItem.value = props.options[
|
|
167
|
-
} else if (option !== undefined) {
|
|
168
|
-
focusedDropDownItem.value = option.value;
|
|
215
|
+
if (nextOptionIndex !== null) {
|
|
216
|
+
focusedDropDownItem.value = props.options[nextOptionIndex].value || null;
|
|
169
217
|
}
|
|
170
218
|
}
|
|
171
219
|
|
|
@@ -174,10 +222,10 @@ function onKeyDownDropDown(e: KeyboardEvent) {
|
|
|
174
222
|
isOpen.value = true;
|
|
175
223
|
|
|
176
224
|
const index = props.options.findIndex(option => option.value === focusedDropDownItem.value);
|
|
177
|
-
const
|
|
225
|
+
const prevOptionIndex = getPrevFocusableSelectOption(index);
|
|
178
226
|
|
|
179
|
-
if (
|
|
180
|
-
focusedDropDownItem.value =
|
|
227
|
+
if (prevOptionIndex !== null) {
|
|
228
|
+
focusedDropDownItem.value = props.options[prevOptionIndex].value || null;
|
|
181
229
|
}
|
|
182
230
|
}
|
|
183
231
|
|
|
@@ -187,6 +235,10 @@ function onKeyDownDropDown(e: KeyboardEvent) {
|
|
|
187
235
|
}
|
|
188
236
|
|
|
189
237
|
function getActiveDropDownItemClasses(option: SelectOption) {
|
|
238
|
+
if (option.isGroupLabel) {
|
|
239
|
+
return {};
|
|
240
|
+
}
|
|
241
|
+
|
|
190
242
|
const variants: Record<InputState, string> = {
|
|
191
243
|
[InputState.base]: '!bg-base-100',
|
|
192
244
|
[InputState.success]: 'bg-success-200',
|
|
@@ -201,16 +253,21 @@ function getActiveDropDownItemClasses(option: SelectOption) {
|
|
|
201
253
|
} : {};
|
|
202
254
|
}
|
|
203
255
|
|
|
204
|
-
function onClickDropDownItem(e: MouseEvent,
|
|
256
|
+
function onClickDropDownItem(e: MouseEvent, option: SelectOption) {
|
|
205
257
|
e.preventDefault();
|
|
258
|
+
|
|
259
|
+
if (option.isGroupLabel) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
|
|
206
263
|
reference.value?.focus();
|
|
207
264
|
|
|
208
265
|
if (props.closeOnSelectItem) {
|
|
209
266
|
isOpen.value = false;
|
|
210
267
|
}
|
|
211
268
|
|
|
212
|
-
emit('selectElement', value);
|
|
213
|
-
_modelValue.value = value;
|
|
269
|
+
emit('selectElement', option.value);
|
|
270
|
+
_modelValue.value = option.value || null;
|
|
214
271
|
}
|
|
215
272
|
|
|
216
273
|
watch(_modelValue, (val) => {
|
|
@@ -236,9 +293,13 @@ watch(_modelValue, (val) => {
|
|
|
236
293
|
<div
|
|
237
294
|
v-for="(option, index) in options"
|
|
238
295
|
:key="`option-${index}`"
|
|
239
|
-
:class="{
|
|
240
|
-
|
|
241
|
-
|
|
296
|
+
:class="{
|
|
297
|
+
...dropDownItemClasses,
|
|
298
|
+
...getActiveDropDownItemClasses(option),
|
|
299
|
+
'font-bold': option.isGroupLabel,
|
|
300
|
+
}"
|
|
301
|
+
@mousedown="(e) => onClickDropDownItem(e, option)"
|
|
302
|
+
@mouseover="() => focusedDropDownItem = !option.isGroupLabel && option.value !== undefined ? option.value : null"
|
|
242
303
|
>
|
|
243
304
|
<slot
|
|
244
305
|
name="contentLeft"
|
|
@@ -9,6 +9,7 @@ export declare const manyOptions: Story;
|
|
|
9
9
|
export declare const nullable: Story;
|
|
10
10
|
export declare const skeleton: Story;
|
|
11
11
|
export declare const disabled: Story;
|
|
12
|
+
export declare const grouped: Story;
|
|
12
13
|
export declare const withPlaceholder: Story;
|
|
13
14
|
export declare const ellipsisText: Story;
|
|
14
15
|
export declare const summary: Story;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.withPlaceholder = exports.summary = exports.skeleton = exports.nullable = exports.manyOptions = exports.ellipsisText = exports.disabled = exports.default = exports.WithSlots = exports.Docs = void 0;
|
|
6
|
+
exports.withPlaceholder = exports.summary = exports.skeleton = exports.nullable = exports.manyOptions = exports.grouped = exports.ellipsisText = exports.disabled = exports.default = exports.WithSlots = exports.Docs = void 0;
|
|
7
7
|
var _Size = require("../../../enums/Size.enum");
|
|
8
8
|
var _AntSelect = _interopRequireDefault(require("../AntSelect.vue"));
|
|
9
9
|
var _AntIcon = _interopRequireDefault(require("../../AntIcon.vue"));
|
|
@@ -230,6 +230,45 @@ const disabled = exports.disabled = {
|
|
|
230
230
|
disabled: true
|
|
231
231
|
}
|
|
232
232
|
};
|
|
233
|
+
const grouped = exports.grouped = {
|
|
234
|
+
render: (args, ctx) => ({
|
|
235
|
+
// @ts-ignore
|
|
236
|
+
components: Docs.render(args, ctx).components,
|
|
237
|
+
// @ts-ignore
|
|
238
|
+
setup: Docs.render(args, ctx).setup,
|
|
239
|
+
template: `
|
|
240
|
+
<AntSelect v-bind="args" v-model="modelValue"/>
|
|
241
|
+
`
|
|
242
|
+
}),
|
|
243
|
+
args: {
|
|
244
|
+
label: "Label",
|
|
245
|
+
description: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod",
|
|
246
|
+
options: [{
|
|
247
|
+
label: "Group 1",
|
|
248
|
+
isGroupLabel: true
|
|
249
|
+
}, {
|
|
250
|
+
label: "Option 1.1",
|
|
251
|
+
value: 1,
|
|
252
|
+
imgUrl: "https://fastly.picsum.photos/id/972/200/200.jpg?hmac=TeAvfwW2T9YMpPW-sWWTeAiseERb12wSeR3mYzuG6TE"
|
|
253
|
+
}, {
|
|
254
|
+
label: "Option 2.1",
|
|
255
|
+
value: 2,
|
|
256
|
+
imgUrl: "https://fastly.picsum.photos/id/314/200/200.jpg?hmac=bCAc2iO5ovLPrvwDQV31aBPS13QTyv33ut2H2wY4QXU"
|
|
257
|
+
}, {
|
|
258
|
+
label: "Group 2",
|
|
259
|
+
isGroupLabel: true
|
|
260
|
+
}, {
|
|
261
|
+
label: "Option 2.1",
|
|
262
|
+
value: 3,
|
|
263
|
+
imgUrl: "https://fastly.picsum.photos/id/972/200/200.jpg?hmac=TeAvfwW2T9YMpPW-sWWTeAiseERb12wSeR3mYzuG6TE"
|
|
264
|
+
}, {
|
|
265
|
+
label: "Option 2.2",
|
|
266
|
+
value: 4,
|
|
267
|
+
imgUrl: "https://fastly.picsum.photos/id/165/200/200.jpg?hmac=tQGrY9pm5ze9soSsZ5CNBt87zqnHfFwdPv_khau12Sw"
|
|
268
|
+
}],
|
|
269
|
+
modelValue: 1
|
|
270
|
+
}
|
|
271
|
+
};
|
|
233
272
|
const withPlaceholder = exports.withPlaceholder = {
|
|
234
273
|
render: Docs.render,
|
|
235
274
|
args: {
|
|
@@ -245,6 +245,52 @@ export const disabled = {
|
|
|
245
245
|
disabled: true
|
|
246
246
|
}
|
|
247
247
|
};
|
|
248
|
+
export const grouped = {
|
|
249
|
+
render: (args, ctx) => ({
|
|
250
|
+
// @ts-ignore
|
|
251
|
+
components: Docs.render(args, ctx).components,
|
|
252
|
+
// @ts-ignore
|
|
253
|
+
setup: Docs.render(args, ctx).setup,
|
|
254
|
+
template: `
|
|
255
|
+
<AntSelect v-bind="args" v-model="modelValue"/>
|
|
256
|
+
`
|
|
257
|
+
}),
|
|
258
|
+
args: {
|
|
259
|
+
label: "Label",
|
|
260
|
+
description: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod",
|
|
261
|
+
options: [
|
|
262
|
+
{
|
|
263
|
+
label: "Group 1",
|
|
264
|
+
isGroupLabel: true
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
label: "Option 1.1",
|
|
268
|
+
value: 1,
|
|
269
|
+
imgUrl: "https://fastly.picsum.photos/id/972/200/200.jpg?hmac=TeAvfwW2T9YMpPW-sWWTeAiseERb12wSeR3mYzuG6TE"
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
label: "Option 2.1",
|
|
273
|
+
value: 2,
|
|
274
|
+
imgUrl: "https://fastly.picsum.photos/id/314/200/200.jpg?hmac=bCAc2iO5ovLPrvwDQV31aBPS13QTyv33ut2H2wY4QXU"
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
label: "Group 2",
|
|
278
|
+
isGroupLabel: true
|
|
279
|
+
},
|
|
280
|
+
{
|
|
281
|
+
label: "Option 2.1",
|
|
282
|
+
value: 3,
|
|
283
|
+
imgUrl: "https://fastly.picsum.photos/id/972/200/200.jpg?hmac=TeAvfwW2T9YMpPW-sWWTeAiseERb12wSeR3mYzuG6TE"
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
label: "Option 2.2",
|
|
287
|
+
value: 4,
|
|
288
|
+
imgUrl: "https://fastly.picsum.photos/id/165/200/200.jpg?hmac=tQGrY9pm5ze9soSsZ5CNBt87zqnHfFwdPv_khau12Sw"
|
|
289
|
+
}
|
|
290
|
+
],
|
|
291
|
+
modelValue: 1
|
|
292
|
+
}
|
|
293
|
+
};
|
|
248
294
|
export const withPlaceholder = {
|
|
249
295
|
render: Docs.render,
|
|
250
296
|
args: {
|