From df5142074d628bae1c56089f1bf83d4f82e3745c Mon Sep 17 00:00:00 2001 From: mertsincan Date: Wed, 24 Jan 2024 10:44:00 +0000 Subject: [PATCH] Fixed #5141 - Add highlightOnSelect and showTick props to Dropdown --- components/lib/dropdown/BaseDropdown.vue | 8 +++++++ components/lib/dropdown/Dropdown.d.ts | 22 +++++++++++++++++ components/lib/dropdown/Dropdown.vue | 24 +++++++++++++------ .../lib/dropdown/style/DropdownStyle.js | 8 +++++-- 4 files changed, 53 insertions(+), 9 deletions(-) diff --git a/components/lib/dropdown/BaseDropdown.vue b/components/lib/dropdown/BaseDropdown.vue index f14ce08a7..7099cd648 100644 --- a/components/lib/dropdown/BaseDropdown.vue +++ b/components/lib/dropdown/BaseDropdown.vue @@ -130,6 +130,14 @@ export default { type: Boolean, default: true }, + highlightOnSelect: { + type: Boolean, + default: false + }, + showTick: { + type: Boolean, + default: true + }, filterMessage: { type: String, default: null diff --git a/components/lib/dropdown/Dropdown.d.ts b/components/lib/dropdown/Dropdown.d.ts index 3bb49f28d..52c75157e 100755 --- a/components/lib/dropdown/Dropdown.d.ts +++ b/components/lib/dropdown/Dropdown.d.ts @@ -143,6 +143,18 @@ export interface DropdownPassThroughOptions { * Used to pass attributes to the item's DOM element. */ item?: DropdownPassThroughOptionType; + /** + * Used to pass attributes to the item label's DOM element. + */ + itemLabel?: DropdownPassThroughOptionType; + /** + * Used to pass attributes to the tick icon's DOM element. + */ + tickIcon?: DropdownPassThroughOptionType; + /** + * Used to pass attributes to the bank icon's DOM element. + */ + blankIcon?: DropdownPassThroughOptionType; /** * Used to pass attributes to the empty message's DOM element. */ @@ -418,6 +430,16 @@ export interface DropdownProps { * @defaultValue true */ 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. * @defaultValue '{0} results are available' diff --git a/components/lib/dropdown/Dropdown.vue b/components/lib/dropdown/Dropdown.vue index a22956844..90b5d33d1 100755 --- a/components/lib/dropdown/Dropdown.vue +++ b/components/lib/dropdown/Dropdown.vue @@ -127,7 +127,13 @@ :data-p-disabled="isOptionDisabled(option)" v-bind="getPTItemOptions(option, getItemOptions, i, 'item')" > - {{ getOptionLabel(option) }} + + + {{ getOptionLabel(option) }} +
  • @@ -169,6 +175,8 @@ diff --git a/components/lib/dropdown/style/DropdownStyle.js b/components/lib/dropdown/style/DropdownStyle.js index 079838082..95ee34469 100644 --- a/components/lib/dropdown/style/DropdownStyle.js +++ b/components/lib/dropdown/style/DropdownStyle.js @@ -61,6 +61,8 @@ const css = ` white-space: nowrap; position: relative; overflow: hidden; + display: flex; + align-items: center; } .p-dropdown-item-group { @@ -134,14 +136,16 @@ const classes = { wrapper: 'p-dropdown-items-wrapper', list: 'p-dropdown-items', itemGroup: 'p-dropdown-item-group', - item: ({ instance, state, option, focusedOption }) => [ + item: ({ instance, props, state, option, focusedOption }) => [ 'p-dropdown-item', { - 'p-highlight': instance.isSelected(option), + 'p-highlight': instance.isSelected(option) && props.highlightOnSelect, 'p-focus': state.focusedOptionIndex === focusedOption, 'p-disabled': instance.isOptionDisabled(option) } ], + tickIcon: 'p-dropdown-tick-icon', + blankIcon: 'p-dropdown-blank-icon', emptyMessage: 'p-dropdown-empty-message' };