@volverjs/ui-vue 0.0.8-beta.3 → 0.0.8-beta.5

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.
@@ -299,34 +299,36 @@
299
299
  loadingLabel: propsDefaults.value.loadingLabel,
300
300
  disabled: disabled.value,
301
301
  readonly: readonly.value,
302
- modifiers: props.modifiers,
303
- options: props.options,
304
- labelKey: props.labelKey,
305
- valueKey: props.valueKey,
306
- icon: props.icon,
307
- iconPosition: props.iconPosition,
308
- floating: props.floating,
309
- unselectable: props.unselectable,
310
- multiple: props.multiple,
311
- label: props.label,
312
- placeholder: props.placeholder,
302
+ modifiers: propsDefaults.value.modifiers,
303
+ options: propsDefaults.value.options,
304
+ labelKey: propsDefaults.value.labelKey,
305
+ valueKey: propsDefaults.value.valueKey,
306
+ icon: propsDefaults.value.icon,
307
+ iconPosition: propsDefaults.value.iconPosition,
308
+ floating: propsDefaults.value.floating,
309
+ unselectable: propsDefaults.value.unselectable,
310
+ multiple: propsDefaults.value.multiple,
311
+ label: propsDefaults.value.label,
312
+ placeholder: propsDefaults.value.placeholder,
313
313
  modelValue: props.modelValue,
314
314
  }))
315
315
 
316
316
  const dropdownProps = computed(() => ({
317
317
  id: hasDropdownId.value,
318
318
  reference: wrapperEl.value,
319
- placement: props.placement,
320
- strategy: props.strategy,
321
- transitionName: props.transitionName,
322
- offset: props.offset,
323
- shift: props.shift,
324
- flip: props.flip,
325
- autoPlacement: props.autoPlacement,
326
- arrow: props.arrow,
327
- autofocusFirst: searchable.value ? false : props.autofocusFirst,
328
- triggerWidth: props.triggerWidth,
329
- modifiers: props.dropdownModifiers,
319
+ placement: propsDefaults.value.placement,
320
+ strategy: propsDefaults.value.strategy,
321
+ transitionName: propsDefaults.value.transitionName,
322
+ offset: propsDefaults.value.offset,
323
+ shift: propsDefaults.value.shift,
324
+ flip: propsDefaults.value.flip,
325
+ autoPlacement: propsDefaults.value.autoPlacement,
326
+ arrow: propsDefaults.value.arrow,
327
+ autofocusFirst: searchable.value
328
+ ? false
329
+ : propsDefaults.value.autofocusFirst,
330
+ triggerWidth: propsDefaults.value.triggerWidth,
331
+ modifiers: propsDefaults.value.dropdownModifiers,
330
332
  }))
331
333
 
332
334
  // slots
@@ -1,4 +1,5 @@
1
1
  import type { Option } from '../types/generic'
2
+ import { get } from 'ts-dot-prop'
2
3
 
3
4
  // eslint-disable-next-line
4
5
  export function useOptions(props: any) {
@@ -11,7 +12,7 @@ export function useOptions(props: any) {
11
12
  return String(
12
13
  typeof labelKey.value === 'function'
13
14
  ? labelKey.value(option)
14
- : option[labelKey.value],
15
+ : get(option, labelKey.value),
15
16
  )
16
17
  }
17
18
 
@@ -20,7 +21,7 @@ export function useOptions(props: any) {
20
21
 
21
22
  return typeof valueKey.value === 'function'
22
23
  ? valueKey.value(option)
23
- : option[valueKey.value]
24
+ : get(option, valueKey.value)
24
25
  }
25
26
 
26
27
  const getOptionDisabled = (option: string | Option): boolean => {
@@ -28,7 +29,7 @@ export function useOptions(props: any) {
28
29
 
29
30
  return typeof disabledKey.value === 'function'
30
31
  ? disabledKey.value(option)
31
- : option[disabledKey.value]
32
+ : get(option, disabledKey.value)
32
33
  }
33
34
 
34
35
  const getOptionGrouped = (option: string | Option) => {
@@ -2,7 +2,6 @@ import type { PlayAttributes } from '@/test/types'
2
2
  import { expect } from '@/test/expect'
3
3
  import { within } from '@storybook/testing-library'
4
4
  import { sleep } from '@/test/sleep'
5
- import { getOptionValue } from '@/test/options'
6
5
  import { defaultTest as selectDefaultTest } from '@/stories/Select/Select.test'
7
6
 
8
7
  export async function defaultTest({ canvasElement, args }: PlayAttributes) {
@@ -49,11 +48,12 @@ export async function defaultTest({ canvasElement, args }: PlayAttributes) {
49
48
  // select first value
50
49
  await expect(dropdownFirstItem).toBeClicked()
51
50
  await sleep()
51
+
52
+ const { getOptionValue } = useOptions(args)
53
+
52
54
  const firstValue = getOptionValue(
53
- args.options[0].options ? args.options[0] : args,
54
- 0,
55
+ args.options[0].options?.[0] ?? args.options[0],
55
56
  )
56
-
57
57
  // in grouped options the first element is not selectable
58
58
  if (args.multiple) {
59
59
  await expect(JSON.parse(value.innerHTML)).toEqual([firstValue])
@@ -66,8 +66,7 @@ export async function defaultTest({ canvasElement, args }: PlayAttributes) {
66
66
  await expect(dropdownSecondItem).toBeClicked()
67
67
  await sleep()
68
68
  const secondValue = getOptionValue(
69
- args.options[0].options ? args.options[0] : args,
70
- 1,
69
+ args.options[0].options?.[1] ?? args.options[1],
71
70
  )
72
71
  if (args.multiple) {
73
72
  await expect(JSON.parse(value.innerHTML)).toEqual([
@@ -76,3 +76,21 @@ export const GroupedOptions: Story = {
76
76
  ],
77
77
  },
78
78
  }
79
+
80
+ export const DotPathOptions: Story = {
81
+ ...Default,
82
+ args: {
83
+ ...Default.args,
84
+ valueKey: 'value.val',
85
+ labelKey: 'label.en',
86
+ options: [
87
+ { value: { val: 'first' }, label: { it: 'Primo', en: 'First' } },
88
+ {
89
+ value: { val: 'second' },
90
+ label: { it: 'Secondo', en: 'Second' },
91
+ },
92
+ { value: { val: 'third' }, label: { it: 'Terzo', en: 'Third' } },
93
+ { value: { val: 'fourth' }, label: { it: 'Quarto', en: 'Fourth' } },
94
+ ],
95
+ },
96
+ }
@@ -2,7 +2,6 @@ import type { PlayAttributes } from '@/test/types'
2
2
  import { within } from '@storybook/testing-library'
3
3
  import { expect } from '@/test/expect'
4
4
  import { sleep } from '@/test/sleep'
5
- import { getOptionValue } from '@/test/options'
6
5
 
7
6
  export async function defaultTest({ canvasElement, args }: PlayAttributes) {
8
7
  const element = (await within(canvasElement).findByTestId(
@@ -16,6 +15,8 @@ export async function defaultTest({ canvasElement, args }: PlayAttributes) {
16
15
  )[0] as HTMLSelectElement
17
16
  const hint = element.getElementsByClassName('vv-select__hint')[0]
18
17
 
18
+ const { getOptionValue } = useOptions(args)
19
+
19
20
  if (
20
21
  !args.invalid &&
21
22
  !args.disabled &&
@@ -25,8 +26,7 @@ export async function defaultTest({ canvasElement, args }: PlayAttributes) {
25
26
  ) {
26
27
  // select first value
27
28
  const firstValue = getOptionValue(
28
- args.options[0].options ? args.options[0] : args,
29
- 0,
29
+ args.options[0].options?.[0] ?? args.options[0],
30
30
  )
31
31
  select.value = firstValue
32
32
  select.dispatchEvent(new Event('change'))