diff --git a/packages/primevue/src/cascadeselect/BaseCascadeSelect.vue b/packages/primevue/src/cascadeselect/BaseCascadeSelect.vue
index fe2b5ad67..55f893579 100644
--- a/packages/primevue/src/cascadeselect/BaseCascadeSelect.vue
+++ b/packages/primevue/src/cascadeselect/BaseCascadeSelect.vue
@@ -18,6 +18,14 @@ export default {
default: '960px'
},
dataKey: null,
+ showClear: {
+ type: Boolean,
+ default: false
+ },
+ clearIcon: {
+ type: String,
+ default: undefined
+ },
inputId: {
type: String,
default: null
diff --git a/packages/primevue/src/cascadeselect/CascadeSelect.d.ts b/packages/primevue/src/cascadeselect/CascadeSelect.d.ts
index a93d66ed7..cc1bf6e4a 100644
--- a/packages/primevue/src/cascadeselect/CascadeSelect.d.ts
+++ b/packages/primevue/src/cascadeselect/CascadeSelect.d.ts
@@ -327,6 +327,15 @@ export interface CascadeSelectProps {
* A property to uniquely identify an option.
*/
dataKey?: string | undefined;
+ /**
+ * When enabled, a clear icon is displayed to clear the value.
+ * @defaultValue false
+ */
+ showClear?: boolean | undefined;
+ /**
+ * Icon to display in clear button.
+ */
+ clearIcon?: string | undefined;
/**
* Identifier of the underlying input element.
*/
@@ -553,6 +562,17 @@ export interface CascadeSelectSlots {
*/
options: any[];
}): VNode[];
+ /**
+ * Custom clear icon template.
+ * @param {Object} scope - clear icon slot's params.
+ */
+ clearicon(scope: {
+ /**
+ * Clear icon click function.
+ * @param {Event} event - Browser event
+ */
+ clearCallback: (event: Event) => void;
+ }): VNode[];
}
/**
diff --git a/packages/primevue/src/cascadeselect/CascadeSelect.vue b/packages/primevue/src/cascadeselect/CascadeSelect.vue
index 188a388f6..8c3c221b8 100644
--- a/packages/primevue/src/cascadeselect/CascadeSelect.vue
+++ b/packages/primevue/src/cascadeselect/CascadeSelect.vue
@@ -30,6 +30,9 @@
{{ label }}
+
+
+
@@ -101,6 +104,7 @@ import OverlayEventBus from 'primevue/overlayeventbus';
import Portal from 'primevue/portal';
import BaseCascadeSelect from './BaseCascadeSelect.vue';
import CascadeSelectSub from './CascadeSelectSub.vue';
+import TimesIcon from '@primevue/icons/times';
export default {
name: 'CascadeSelect',
@@ -383,7 +387,9 @@ export default {
return;
}
- if (!this.overlay || !this.overlay.contains(event.target)) {
+ if (event.target.getAttribute('data-pc-section') === 'clearicon' || event.target.closest('[data-pc-section="clearicon"]')) {
+ return;
+ } else if (!this.overlay || !this.overlay.contains(event.target)) {
this.overlayVisible ? this.hide() : this.show();
focus(this.$refs.focusInput);
}
@@ -391,6 +397,9 @@ export default {
this.clicked = true;
this.$emit('click', event);
},
+ onClearClick(event) {
+ this.updateModel(event, null);
+ },
onOverlayClick(event) {
OverlayEventBus.emit('overlay-click', {
originalEvent: event,
@@ -841,14 +850,18 @@ export default {
},
focusedOptionId() {
return this.focusedOptionInfo.index !== -1 ? `${this.id}${isNotEmpty(this.focusedOptionInfo.parentKey) ? '_' + this.focusedOptionInfo.parentKey : ''}_${this.focusedOptionInfo.index}` : null;
+ },
+ isClearIconVisible() {
+ return this.showClear && this.d_value != null && isNotEmpty(this.options);
}
},
components: {
- CascadeSelectSub: CascadeSelectSub,
- Portal: Portal,
- ChevronDownIcon: ChevronDownIcon,
- SpinnerIcon: SpinnerIcon,
- AngleRightIcon: AngleRightIcon
+ CascadeSelectSub,
+ Portal,
+ ChevronDownIcon,
+ SpinnerIcon,
+ AngleRightIcon,
+ TimesIcon
}
};
diff --git a/packages/primevue/src/cascadeselect/style/CascadeSelectStyle.d.ts b/packages/primevue/src/cascadeselect/style/CascadeSelectStyle.d.ts
index dfd38f03a..9cf49c015 100644
--- a/packages/primevue/src/cascadeselect/style/CascadeSelectStyle.d.ts
+++ b/packages/primevue/src/cascadeselect/style/CascadeSelectStyle.d.ts
@@ -26,6 +26,10 @@ export enum CascadeSelectClasses {
* Class name of the loading icon element
*/
loadingIcon = 'p-cascadeselect-loading-icon',
+ /**
+ * Class name of the dropdown icon element
+ */
+ clearIcon = 'p-cascadeselect-clear-icon',
/**
* Class name of the dropdown icon element
*/
diff --git a/packages/primevue/src/cascadeselect/style/CascadeSelectStyle.js b/packages/primevue/src/cascadeselect/style/CascadeSelectStyle.js
index 0337b74c2..268e59dd7 100644
--- a/packages/primevue/src/cascadeselect/style/CascadeSelectStyle.js
+++ b/packages/primevue/src/cascadeselect/style/CascadeSelectStyle.js
@@ -60,6 +60,14 @@ const theme = ({ dt }) => `
border-end-end-radius: ${dt('border.radius.md')};
}
+.p-cascadeselect-clear-icon {
+ position: absolute;
+ top: 50%;
+ margin-top: -0.5rem;
+ color: ${dt('cascadeselect.clear.icon.color')};
+ inset-inline-end: ${dt('cascadeselect.dropdown.width')};
+}
+
.p-cascadeselect-label {
display: block;
white-space: nowrap;
@@ -262,6 +270,7 @@ const classes = {
'p-cascadeselect-label-empty': !instance.$slots['value'] && (instance.label === 'p-emptylabel' || instance.label.length === 0)
}
],
+ clearIcon: 'p-cascadeselect-clear-icon',
dropdown: 'p-cascadeselect-dropdown',
loadingIcon: 'p-cascadeselect-loading-icon',
dropdownIcon: 'p-cascadeselect-dropdown-icon',