Skip to content

Commit

Permalink
Fix epicmaxco#1080 epicmaxco#1172: Select supports numbers, no-void c…
Browse files Browse the repository at this point in the history
…heck removed
  • Loading branch information
Derranion authored and m0ksem committed Oct 27, 2021
1 parent 6f90251 commit 9fcc254
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/docs/src/locales/en/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3111,7 +3111,7 @@
"api": {
"icons": "Used to configure icon fonts and aliases.",
"components": "Used to globally overwrite props of specific components.",
"componentsAll": "Used to globally set props of all components. If there are no other source of props.",
"componentsAll": "Used to globally set props for all components. If there are no other source of props.",
"colors": "Used to define theme colors that components make use of. Here you can redefine default Vuestic-theme colors."
}
},
Expand Down
1 change: 1 addition & 0 deletions packages/ui/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module.exports = {
'id-match': ['error', '^[A-Za-z0-9-_$]+$', { properties: true }], // To prevent cyrillic letters etc.
'vue/html-closing-bracket-spacing': 'error',
'vue/no-multiple-template-root': 'off',
'no-void': ['error', { allowAsStatement: true }],
},
ignorePatterns: ['**/*spec.disabled.*', '**/wip-*/**'],
}
1 change: 1 addition & 0 deletions packages/ui/src/components/va-select/VaSelect.demo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@
label="At least 1 option should be selected"
:options="validationSelect.options"
:rules="validationSelect.rules.required"
multiple
/>
<va-select
v-model="validationSelect.multipleValue"
Expand Down
8 changes: 4 additions & 4 deletions packages/ui/src/components/va-select/VaSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ export default defineComponent({
}
if (Array.isArray(value)) {
warn('Model value should be a string for a single Select.')
warn('Model value should be a string or a number for a single Select.')
if (value.length) {
return value[value.length - 1]
Expand All @@ -292,9 +292,9 @@ export default defineComponent({
},
})
const valueComputedString = computed((): string => {
const valueComputedString = computed((): string | number => {
if (!valueComputed.value) { return props.clearValue }
if (typeof valueComputed.value === 'string') { return valueComputed.value }
if (typeof valueComputed.value === 'string' || typeof valueComputed.value === 'number') { return valueComputed.value }
if (Array.isArray(valueComputed.value)) {
return valueComputed.value.map((value) => getText(value)).join(props.separator) || props.clearValue
}
Expand Down Expand Up @@ -385,7 +385,7 @@ export default defineComponent({
addOption(option)
}
} else {
valueComputed.value = typeof option === 'string' ? option : { ...option }
valueComputed.value = typeof option === 'string' || typeof option === 'number' ? option : { ...option }
hideAndFocus()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ class SelectOptionListProps {
multiple = prop<boolean>({ type: Boolean, default: false })
search = prop<string>({ type: String, default: '' })
hoveredOption = prop<string | object>({
type: [String, Object],
hoveredOption = prop<string | number | object>({
type: [String, Number, Object],
default: null,
})
Expand Down
11 changes: 8 additions & 3 deletions packages/ui/src/composables/useSelectableList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@ export const useSelectableListProps = {
export function useSelectableList (props: any) {
const isSelectableListComponent = true

const isStringOrNumber = (option: any): boolean => {
const typeOfOption = typeof option
return typeOfOption === 'string' || typeOfOption === 'number'
}

const getValue = (option: any) => {
if (!props.valueBy) { return option }

return typeof option === 'string'
return isStringOrNumber(option)
? option
: getProp(option, props.valueBy)
}
Expand All @@ -31,7 +36,7 @@ export function useSelectableList (props: any) {
}

const getText = (option: any): any => {
return typeof option === 'string' || typeof option === 'number'
return isStringOrNumber(option)
? option
: getProp(option, props.textBy)
}
Expand All @@ -41,7 +46,7 @@ export function useSelectableList (props: any) {
}

const getTrackBy = (option: any) => {
return typeof option === 'string'
return isStringOrNumber(option)
? option
: getProp(option, props.trackBy)
}
Expand Down

0 comments on commit 9fcc254

Please sign in to comment.