Skip to content

Commit

Permalink
fix: #5060, Dropdown: After selecting an option, clearing the value u…
Browse files Browse the repository at this point in the history
…sing close icon should clear the filter input (#5061)

* fix: #5060, Dropdown: After selecting an option, clearing the value using close icon should clear the filter input

* fix: #5060, Dropdown: After selecting an option, clearing the value using close icon should clear the filter input

---------

Co-authored-by: Akshay Antony <[email protected]>
  • Loading branch information
akshayaqburst and akshayantony55 authored Jan 16, 2024
1 parent 6b75f1a commit 6f71f81
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 1 deletion.
6 changes: 6 additions & 0 deletions api-generator/components/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ const DropdownProps = [
default: 'false',
description: 'Clears the filter value when hiding the dropdown.'
},
{
name: 'resetFilterOnClear',
type: 'boolean',
default: 'false',
description: 'Clears the filter value when clicking on the clear icon.'
},
{
name: 'virtualScrollerOptions',
type: 'object',
Expand Down
4 changes: 4 additions & 0 deletions components/lib/dropdown/BaseDropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ export default {
type: Boolean,
default: false
},
resetFilterOnClear: {
type: Boolean,
default: false
},
virtualScrollerOptions: {
type: Object,
default: null
Expand Down
5 changes: 5 additions & 0 deletions components/lib/dropdown/Dropdown.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,11 @@ export interface DropdownProps {
* @defaultValue false
*/
resetFilterOnHide?: boolean;
/**
* Clears the filter value when clicking on the clear icon.
* @defaultValue false
*/
resetFilterOnClear?: boolean;
/**
* Whether to use the virtualScroller feature. The properties of VirtualScroller component can be used like an object in it.
*/
Expand Down
1 change: 1 addition & 0 deletions components/lib/dropdown/Dropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ export default {
},
onClearClick(event) {
this.updateModel(event, null);
this.resetFilterOnClear && (this.filterValue = null);
},
onFirstHiddenFocus(event) {
const focusableEl = event.relatedTarget === this.$refs.focusInput ? DomHandler.getFirstFocusableElement(this.overlay, ':not([data-p-hidden-focusable="true"])') : this.$refs.focusInput;
Expand Down
8 changes: 8 additions & 0 deletions doc/common/apidoc/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -24158,6 +24158,14 @@
"default": "false",
"description": "Clears the filter value when hiding the dropdown."
},
{
"name": "resetFilterOnClear",
"optional": true,
"readonly": false,
"type": "boolean",
"default": "false",
"description": "Clears the filter value when clicking on the dropdown."
},
{
"name": "virtualScrollerOptions",
"optional": true,
Expand Down
2 changes: 1 addition & 1 deletion doc/dropdown/FilterDoc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<p>Dropdown provides built-in filtering that is enabled by adding the <i>filter</i> property.</p>
</DocSectionText>
<div class="card flex justify-content-center">
<Dropdown v-model="selectedCountry" :options="countries" filter optionLabel="name" placeholder="Select a Country" class="w-full md:w-14rem">
<Dropdown v-model="selectedCountry" :options="countries" filter optionLabel="name" placeholder="Select a Country" class="w-full md:w-14rem" showClear>
<template #value="slotProps">
<div v-if="slotProps.value" class="flex align-items-center">
<img :alt="slotProps.value.label" src="https://primefaces.org/cdn/primevue/images/flag/flag_placeholder.png" :class="`mr-2 flag flag-${slotProps.value.code.toLowerCase()}`" style="width: 18px" />
Expand Down

0 comments on commit 6f71f81

Please sign in to comment.