Skip to content

Commit

Permalink
feat(UI): BaseSelect disabled state
Browse files Browse the repository at this point in the history
  • Loading branch information
toriphes committed May 10, 2022
1 parent 1869e6a commit 2b436d8
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/renderer/components/BaseSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<div
ref="el"
class="select"
:class="{'select-open': isOpen}"
:class="{'select-open': isOpen, 'select--disabled': disabled}"
role="combobox"
:tabindex="searchable ? -1 : tabindex"
:tabindex="searchable || disabled ? -1 : tabindex"
@focus="activate()"
@blur="searchable ? false : handleBlurEvent()"
@keyup.esc="deactivate()"
Expand Down Expand Up @@ -98,13 +98,11 @@ export default defineComponent({
},
optionTrackBy: {
type: [String, Function],
default: () => (opt) => {
for (const guess of ['id', 'value']) if (opt[guess]) return guess;
}
default: 'value'
},
optionLabel: {
type: [String, Function],
default: () => (opt) => opt.label ? 'label' : undefined
default: 'label'
},
groupLabel: {
type: String
Expand All @@ -126,6 +124,10 @@ export default defineComponent({
},
dropdownClass: {
type: String
},
disabled: {
type: Boolean,
default: false
}
},
emits: ['select', 'open', 'close', 'update:modelValue', 'change', 'blur'],
Expand All @@ -143,8 +145,10 @@ export default defineComponent({
const getOptionLabel = (opt) => _guess('optionLabel', opt);
const _guess = (name, item) => {
const prop = props[name];
const key = typeof prop === 'function' ? prop(item) : prop;
return key ? item[key] : item;
if (typeof prop === 'function')
return prop(item);
return item[prop] || item;
};
const flattenOptions = computed(() => {
Expand Down Expand Up @@ -231,7 +235,7 @@ export default defineComponent({
};
const activate = () => {
if (isOpen.value) return;
if (isOpen.value || props.disabled) return;
isOpen.value = true;
hightlightedIndex.value = flattenOptions.value.findIndex(el => el.value === internalValue.value) || 0;
Expand Down Expand Up @@ -365,5 +369,9 @@ export default defineComponent({
list-style: none;
}
&--disabled {
opacity: 0.6;
cursor: not-allowed;
}
}
</style>

0 comments on commit 2b436d8

Please sign in to comment.