Skip to content

Commit

Permalink
fix(input-dropdown): remove button is displayed even when item is not…
Browse files Browse the repository at this point in the history
… removable (#155) (#165)

fix #155

Co-authored-by: Kia Ishii <kia.king.08@gmail.com>
  • Loading branch information
brc-dd and kiaking committed Oct 20, 2022
1 parent 45b3ae3 commit 49ff573
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
9 changes: 9 additions & 0 deletions lib/components/SInputDropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ const hasSelected = computed(() => {
return selected.value.length > 0
})
const removable = computed(() => {
if (isArray(props.modelValue)) {
return props.nullable || selected.value.length > 1
}
return !!props.nullable
})
async function handleOpen() {
!props.disabled && open()
}
Expand Down Expand Up @@ -137,6 +145,7 @@ function handleArray(value: OptionValue) {
<SInputDropdownItem
v-if="hasSelected"
:items="selected"
:removable="removable"
:disabled="disabled ?? false"
@remove="handleSelect"
/>
Expand Down
3 changes: 3 additions & 0 deletions lib/components/SInputDropdownItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface ItemAvatar extends ItemBase {
defineProps<{
items: Item[]
removable: boolean
disabled: boolean
}>()
Expand All @@ -37,6 +38,7 @@ defineEmits<{
v-if="item.type === 'text' || item.type === undefined"
:label="item.label"
:value="item.value"
:removable="removable"
:disabled="disabled"
@remove="(v) => $emit('remove', v)"
/>
Expand All @@ -45,6 +47,7 @@ defineEmits<{
:label="item.label"
:image="item.image"
:value="item.value"
:removable="removable"
:disabled="disabled"
@remove="(v) => $emit('remove', v)"
/>
Expand Down
11 changes: 8 additions & 3 deletions lib/components/SInputDropdownItemAvatar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ defineProps<{
label: string
image?: string | null
value: string | number | boolean
removable: boolean
disabled: boolean
}>()
Expand All @@ -16,15 +17,15 @@ defineEmits<{
</script>

<template>
<div class="SInputDropdownItemAvatar" :class="{ disabled }">
<div class="SInputDropdownItemAvatar" :class="{ disabled, removable }">
<div class="user">
<div class="avatar">
<SAvatar size="nano" :avatar="image" :name="label" />
</div>
<p class="name">{{ label }}</p>
</div>

<div v-if="!disabled" class="remove" role="button" @click="$emit('remove', value)">
<div v-if="!disabled && removable" class="remove" role="button" @click="$emit('remove', value)">
<div class="remove-box">
<SIcon :icon="IconX" class="remove-icon" />
</div>
Expand All @@ -37,10 +38,14 @@ defineEmits<{
display: flex;
border: 1px solid var(--c-divider-light);
border-radius: 14px;
padding: 0;
padding: 0 12px 0 0;
background-color: var(--c-bg-mute);
}
.SInputDropdownItemAvatar.removable {
padding: 0;
}
.SInputDropdownItemUserAvatar.disabled {
padding: 0 10px 0 0;
background-color: var(--c-gray-light-4);
Expand Down
13 changes: 9 additions & 4 deletions lib/components/SInputDropdownItemText.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import SIcon from './SIcon.vue'
defineProps<{
label: string
value: string | number | boolean
removable: boolean
disabled: boolean
}>()
Expand All @@ -14,10 +15,10 @@ defineEmits<{
</script>

<template>
<div class="SInputDropdownItemText" :class="{ disabled }">
<div class="SInputDropdownItemText" :class="{ disabled, removable }">
<p class="text">{{ label }}</p>

<div v-if="!disabled" class="remove" role="button" @click.stop="$emit('remove', value)">
<div v-if="!disabled && removable" class="remove" role="button" @click.stop="$emit('remove', value)">
<div class="remove-box">
<SIcon :icon="IconX" class="remove-icon" />
</div>
Expand All @@ -30,12 +31,16 @@ defineEmits<{
display: flex;
border: 1px solid var(--c-divider-light);
border-radius: 14px;
padding: 0 0 0 12px;
padding: 0 12px;
background-color: var(--c-bg-mute);
}
.SInputDropdownItemText.removable {
padding: 0 0 0 12px;
}
.SInputDropdownItemText.disabled {
padding: 0 10px 0;
padding: 0 10px;
background-color: var(--c-gray-light-4);
.text {
Expand Down
2 changes: 1 addition & 1 deletion stories/components/SInputDropdown.story.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const options = [
label="Dropdown input"
placeholder="Please select items"
:options="options"
:nullable="true"
nullable
v-model="value"
/>
</Story>
Expand Down

0 comments on commit 49ff573

Please sign in to comment.