Fixed #5141 - Add highlightOnSelect and showTick props to Dropdown
parent
a4ad0bba81
commit
df5142074d
|
@ -130,6 +130,14 @@ export default {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: true
|
default: true
|
||||||
},
|
},
|
||||||
|
highlightOnSelect: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
showTick: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
filterMessage: {
|
filterMessage: {
|
||||||
type: String,
|
type: String,
|
||||||
default: null
|
default: null
|
||||||
|
|
|
@ -143,6 +143,18 @@ export interface DropdownPassThroughOptions<T = any> {
|
||||||
* Used to pass attributes to the item's DOM element.
|
* Used to pass attributes to the item's DOM element.
|
||||||
*/
|
*/
|
||||||
item?: DropdownPassThroughOptionType<T>;
|
item?: DropdownPassThroughOptionType<T>;
|
||||||
|
/**
|
||||||
|
* Used to pass attributes to the item label's DOM element.
|
||||||
|
*/
|
||||||
|
itemLabel?: DropdownPassThroughOptionType<T>;
|
||||||
|
/**
|
||||||
|
* Used to pass attributes to the tick icon's DOM element.
|
||||||
|
*/
|
||||||
|
tickIcon?: DropdownPassThroughOptionType<T>;
|
||||||
|
/**
|
||||||
|
* Used to pass attributes to the bank icon's DOM element.
|
||||||
|
*/
|
||||||
|
blankIcon?: DropdownPassThroughOptionType<T>;
|
||||||
/**
|
/**
|
||||||
* Used to pass attributes to the empty message's DOM element.
|
* Used to pass attributes to the empty message's DOM element.
|
||||||
*/
|
*/
|
||||||
|
@ -418,6 +430,16 @@ export interface DropdownProps {
|
||||||
* @defaultValue true
|
* @defaultValue true
|
||||||
*/
|
*/
|
||||||
focusOnHover?: boolean | undefined;
|
focusOnHover?: boolean | undefined;
|
||||||
|
/**
|
||||||
|
* Highlights automatically the first item.
|
||||||
|
* @defaultValue false
|
||||||
|
*/
|
||||||
|
highlightOnSelect?: boolean | undefined;
|
||||||
|
/**
|
||||||
|
* Whether the selected option will be shown with a tick.
|
||||||
|
* @defaultValue true
|
||||||
|
*/
|
||||||
|
showTick?: boolean | undefined;
|
||||||
/**
|
/**
|
||||||
* Text to be displayed in hidden accessible field when filtering returns any results. Defaults to value from PrimeVue locale configuration.
|
* Text to be displayed in hidden accessible field when filtering returns any results. Defaults to value from PrimeVue locale configuration.
|
||||||
* @defaultValue '{0} results are available'
|
* @defaultValue '{0} results are available'
|
||||||
|
|
|
@ -127,7 +127,13 @@
|
||||||
:data-p-disabled="isOptionDisabled(option)"
|
:data-p-disabled="isOptionDisabled(option)"
|
||||||
v-bind="getPTItemOptions(option, getItemOptions, i, 'item')"
|
v-bind="getPTItemOptions(option, getItemOptions, i, 'item')"
|
||||||
>
|
>
|
||||||
<slot name="option" :option="option" :index="getOptionIndex(i, getItemOptions)">{{ getOptionLabel(option) }}</slot>
|
<template v-if="showTick">
|
||||||
|
<CheckIcon v-if="isSelected(option)" :class="cx('tickIcon')" v-bind="ptm('tickIcon')" />
|
||||||
|
<BlankIcon v-else :class="cx('blankIcon')" v-bind="ptm('blankIcon')" />
|
||||||
|
</template>
|
||||||
|
<slot name="option" :option="option" :index="getOptionIndex(i, getItemOptions)">
|
||||||
|
<span v-bind="ptm('itemLabel')">{{ getOptionLabel(option) }}</span>
|
||||||
|
</slot>
|
||||||
</li>
|
</li>
|
||||||
</template>
|
</template>
|
||||||
<li v-if="filterValue && (!items || (items && items.length === 0))" :class="cx('emptyMessage')" role="option" v-bind="ptm('emptyMessage')" :data-p-hidden-accessible="true">
|
<li v-if="filterValue && (!items || (items && items.length === 0))" :class="cx('emptyMessage')" role="option" v-bind="ptm('emptyMessage')" :data-p-hidden-accessible="true">
|
||||||
|
@ -169,6 +175,8 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { FilterService } from 'primevue/api';
|
import { FilterService } from 'primevue/api';
|
||||||
|
import BlankIcon from 'primevue/icons/blank';
|
||||||
|
import CheckIcon from 'primevue/icons/check';
|
||||||
import ChevronDownIcon from 'primevue/icons/chevrondown';
|
import ChevronDownIcon from 'primevue/icons/chevrondown';
|
||||||
import FilterIcon from 'primevue/icons/filter';
|
import FilterIcon from 'primevue/icons/filter';
|
||||||
import SpinnerIcon from 'primevue/icons/spinner';
|
import SpinnerIcon from 'primevue/icons/spinner';
|
||||||
|
@ -962,12 +970,14 @@ export default {
|
||||||
ripple: Ripple
|
ripple: Ripple
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
VirtualScroller: VirtualScroller,
|
VirtualScroller,
|
||||||
Portal: Portal,
|
Portal,
|
||||||
TimesIcon: TimesIcon,
|
TimesIcon,
|
||||||
ChevronDownIcon: ChevronDownIcon,
|
ChevronDownIcon,
|
||||||
SpinnerIcon: SpinnerIcon,
|
SpinnerIcon,
|
||||||
FilterIcon: FilterIcon
|
FilterIcon,
|
||||||
|
CheckIcon,
|
||||||
|
BlankIcon
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -61,6 +61,8 @@ const css = `
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
position: relative;
|
position: relative;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.p-dropdown-item-group {
|
.p-dropdown-item-group {
|
||||||
|
@ -134,14 +136,16 @@ const classes = {
|
||||||
wrapper: 'p-dropdown-items-wrapper',
|
wrapper: 'p-dropdown-items-wrapper',
|
||||||
list: 'p-dropdown-items',
|
list: 'p-dropdown-items',
|
||||||
itemGroup: 'p-dropdown-item-group',
|
itemGroup: 'p-dropdown-item-group',
|
||||||
item: ({ instance, state, option, focusedOption }) => [
|
item: ({ instance, props, state, option, focusedOption }) => [
|
||||||
'p-dropdown-item',
|
'p-dropdown-item',
|
||||||
{
|
{
|
||||||
'p-highlight': instance.isSelected(option),
|
'p-highlight': instance.isSelected(option) && props.highlightOnSelect,
|
||||||
'p-focus': state.focusedOptionIndex === focusedOption,
|
'p-focus': state.focusedOptionIndex === focusedOption,
|
||||||
'p-disabled': instance.isOptionDisabled(option)
|
'p-disabled': instance.isOptionDisabled(option)
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
tickIcon: 'p-dropdown-tick-icon',
|
||||||
|
blankIcon: 'p-dropdown-blank-icon',
|
||||||
emptyMessage: 'p-dropdown-empty-message'
|
emptyMessage: 'p-dropdown-empty-message'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue