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

fix(VaSelect #4064): option slot #4097

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
>
<slot name="label" v-bind="bind" />
</VaInputLabel>

<slot name="option-content" />
<slot v-bind="{ ariaAttributes: { ...messagesChildAriaAttributes, ...ariaAttributes }, value: vModel }">
<input v-bind="{ ...messagesChildAriaAttributes, ...ariaAttributes }" v-model="vModel" :placeholder="$props.placeholder" :readonly="$props.readonly" :disabled="$props.disabled" />
</slot>
Expand Down
16 changes: 16 additions & 0 deletions packages/ui/src/components/va-select/VaSelect.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,19 @@ export const AutocompleteMultiple: StoryFn = () => ({

template: '<VaSelect v-model="value" :options="options" autocomplete multiple />',
})

export const optionSlot: StoryFn = () => ({
components: { Component: VaSelect },

data () {
return { value: 'two', options: ['one', 'two', 'tree'] }
},

template: `
<Component v-model="value" :options="options">
<template #option-content="{ option }">
<div class="mr-2">custom: {{ option }}</div>
</template>
</Component>
`,
})
1 change: 1 addition & 0 deletions packages/ui/src/components/va-select/VaSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
v-slot="slotData"
>
<slot name="option" v-bind="slotData || {}" />
<slot name="option-content" v-bind="slotData || {}" />
</va-select-option-list>
</va-dropdown-content>
</va-dropdown>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,29 @@
:style="optionStyle"
:aria-selected="isSelected"
>
<va-icon
v-if="optionIcon"
size="small"
class="va-select-option__icon"
:name="optionIcon"
/>
{{ optionTextSplitted.start }}
<span
v-if="optionTextSplitted.searchedSubString"
class="va-select-option__highlighted"
>
{{ optionTextSplitted.searchedSubString }}
</span>
{{ optionTextSplitted.end }}
<va-icon
v-show="isSelected"
class="va-select-option__selected-icon"
size="small"
name="va-check"
:color="optionIconColor"
/>
<slot>
<va-icon
v-if="optionIcon"
size="small"
class="va-select-option__icon"
:name="optionIcon"
/>
{{ optionTextSplitted.start }}
<span
v-if="optionTextSplitted.searchedSubString"
class="va-select-option__highlighted"
>
{{ optionTextSplitted.searchedSubString }}
</span>
{{ optionTextSplitted.end }}
<va-icon
v-show="isSelected"
class="va-select-option__selected-icon"
size="small"
name="va-check"
:color="optionIconColor"
/>
</slot>
</div>
</template>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,33 @@
@scroll:bottom="handleScrollToBottom"
v-slot="{ item: option, index }"
>
<slot v-bind="{ option, index, selectOption }">
<va-select-option
:option="option"
:current-option="currentOptionComputed"
:disabled="getDisabled(option)"
v-bind="selectOptionProps"
@click.stop="selectHoveredOption"
@mouseenter="handleMouseEnter(option)"
@mousemove="handleMouseMove(option)"
>
<slot v-bind="{ option, index, selectOption }" />
</va-select-option>
</va-virtual-scroller>

<template v-else>
<template v-for="(option, index) in options" :key="getTrackBy(option)">
<va-select-option
:option="option"
:ref="setItemRef(getTrackBy(option))"
:current-option="currentOptionComputed"
:option="option"
:disabled="getDisabled(option)"
v-bind="selectOptionProps"
@click.stop="selectHoveredOption"
@mouseenter="handleMouseEnter(option)"
@mousemove="handleMouseMove(option)"
/>
</slot>
</va-virtual-scroller>

<template v-else>
<template v-for="(option, index) in options" :key="getTrackBy(option)">
<slot v-bind="{ option, index, selectOption }">
<va-select-option
:ref="setItemRef(getTrackBy(option))"
:current-option="currentOptionComputed"
:option="option"
:disabled="getDisabled(option)"
v-bind="selectOptionProps"
@click.stop="selectHoveredOption"
@mouseenter="handleMouseEnter(option)"
@mousemove="handleMouseMove(option)"
/>
</slot>
>
<slot v-bind="{ option, index, selectOption }" />
</va-select-option>
</template>
</template>
</template>
Expand Down
Loading