Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [Select] - fix bug #412 - review disabled behavior #413

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 43 additions & 11 deletions packages/components/select/src/select.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<template>
<div
v-on-click-outside="closeOptions"
class="puik-select"
:class="[
'puik-select',
{ 'puik-select--disabled': props.disabled }
]"
:data-test="dataTest != undefined ? `select-${dataTest}` : undefined"
@keydown.esc="closeOptions"
@keydown.up.prevent.stop="handleKeyDown"
Expand Down Expand Up @@ -43,18 +46,20 @@
>
<PuikIcon
v-if="props.prependInputIcon"
:is-disabled="props.disabled"
:icon="props.prependInputIcon"
/>
<PuikIcon
class="puik-multi-select__dropdown-icon"
:is-disabled="props.disabled"
icon="unfold_more"
/>
<puik-chip
v-for="(option, index) in selectedMultipleOptions"
:id="`chip-${option[props.optionLabelKey]}`"
:key="option[props.optionValueKey]"
:content="option[props.optionLabelKey]"
:disabled="option[props.optionDisabledKey]"
:disabled="option[props.optionDisabledKey] || props.disabled"
size="small"
role="option"
:aria-selected="true"
Expand Down Expand Up @@ -93,10 +98,16 @@
v-if="props.prependInputIcon"
#prepend
>
<PuikIcon :icon="props.prependInputIcon" />
<PuikIcon
:is-disabled="props.disabled"
:icon="props.prependInputIcon"
/>
</template>
<template #append>
<PuikIcon icon="unfold_more" />
<PuikIcon
:is-disabled="props.disabled"
icon="unfold_more"
/>
</template>
</puik-input>
<input
Expand Down Expand Up @@ -135,10 +146,16 @@
v-if="props.prependInputIcon"
#prepend
>
<PuikIcon :icon="props.prependInputIcon" />
<PuikIcon
:is-disabled="props.disabled"
:icon="props.prependInputIcon"
/>
</template>
<template #append>
<PuikIcon icon="unfold_more" />
<PuikIcon
:is-disabled="props.disabled"
icon="unfold_more"
/>
</template>
</puik-input>

Expand Down Expand Up @@ -169,10 +186,16 @@
v-if="props.prependInputIcon"
#prepend
>
<PuikIcon :icon="props.prependInputIcon" />
<PuikIcon
:is-disabled="props.disabled"
:icon="props.prependInputIcon"
/>
</template>
<template #append>
<PuikIcon icon="unfold_more" />
<PuikIcon
:is-disabled="props.disabled"
icon="unfold_more"
/>
</template>
</puik-input>

Expand All @@ -198,11 +221,15 @@
props.searchPlaceholder ?? `${t('puik.select.searchPlaceholder')}`
"
role="searchbox"
:disabled="props.disabled"
:data-test="dataTest != undefined ? `select-search-input-${dataTest}` : undefined"
@input="searchOptions"
>
<template #prepend>
<PuikIcon icon="search" />
<PuikIcon
:is-disabled="props.disabled"
icon="search"
/>
</template>
</puik-input>

Expand All @@ -216,6 +243,7 @@
: `${t('puik.select.selectAll')}`
"
:indeterminate="selectAllIndeterminate"
:disabled="props.disabled"
role="checkbox"
:aria-checked="IsAllSelectedRef"
tabindex="0"
Expand All @@ -236,7 +264,7 @@
: selectedSingleOption === option
"
:option="option"
:disabled="option[props.optionDisabledKey]"
:disabled="option[props.optionDisabledKey] || props.disabled"
:multi-select="props.multiSelect"
:data-test="dataTest != undefined ? `select-option-${index + 1}-${dataTest}` : undefined"
@select="selectOption(option)"
Expand Down Expand Up @@ -406,26 +434,29 @@ const handleSelectAllClick = () => {
};

const toggleOptions = () => {
if (props.disabled) return;
openRef.value = !openRef.value;
emit('open', openRef.value);
resetSearchQuery();
handleDropdownPosition();
};
const openOptions = () => {
if (props.disabled) return;
openRef.value = true;
emit('open', true);
resetSearchQuery();
handleDropdownPosition();
};
const closeOptions = () => {
if (props.disabled) return;
openRef.value = false;
emit('open', false);
resetSearchQuery();
handleDropdownPosition();
};

const selectOption = (option: OptionType) => {
if (!option[props.optionDisabledKey]) {
if (!option[props.optionDisabledKey] || !props.disabled) {
if (props.multiSelect) {
if (selectedMultipleOptions.value.includes(option)) {
selectedMultipleOptions.value = selectedMultipleOptions.value.filter(
Expand All @@ -447,6 +478,7 @@ const selectOption = (option: OptionType) => {
};

const deselectOption = (option: OptionType) => {
if (props.disabled) return;
selectedMultipleOptions.value = selectedMultipleOptions.value.filter(
(opt) => opt !== option
);
Expand Down
7 changes: 7 additions & 0 deletions packages/theme/src/puik-select.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

.puik-select {
@extend .puik-body-default;

&--disabled {
#select-combobox {
@apply cursor-not-allowed;
}
}

&__container {
@apply flex flex-col relative;
}
Expand Down
Loading