From b666789c8a4fe8e16072be6d0e0ca7c59f5c2d11 Mon Sep 17 00:00:00 2001 From: Quinten Coret <33397397+Coretteket@users.noreply.github.com> Date: Mon, 9 Oct 2023 11:36:37 +0200 Subject: [PATCH] Fix ambigious clearing behaviour on SelectButton (#4107) --- api-generator/components/selectbutton.js | 6 ++++++ components/lib/selectbutton/BaseSelectButton.vue | 4 ++++ components/lib/selectbutton/SelectButton.d.ts | 8 +++++++- components/lib/selectbutton/SelectButton.vue | 2 +- doc/common/apidoc/index.json | 9 +++++++++ 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/api-generator/components/selectbutton.js b/api-generator/components/selectbutton.js index 93a2641ea1..6dd55ad81b 100644 --- a/api-generator/components/selectbutton.js +++ b/api-generator/components/selectbutton.js @@ -51,6 +51,12 @@ const SelectButtonProps = [ name: 'unselectable', type: 'boolean', default: 'false', + description: 'Whether selection can not be cleared.' + }, + { + name: 'allowEmpty', + type: 'boolean', + default: 'true', description: 'Whether selection can be cleared.' }, { diff --git a/components/lib/selectbutton/BaseSelectButton.vue b/components/lib/selectbutton/BaseSelectButton.vue index 7ea87474c3..c2018299f9 100644 --- a/components/lib/selectbutton/BaseSelectButton.vue +++ b/components/lib/selectbutton/BaseSelectButton.vue @@ -16,6 +16,10 @@ export default { type: Boolean, default: false }, + allowEmpty: { + type: Boolean, + default: true + }, disabled: Boolean, dataKey: null, 'aria-labelledby': { diff --git a/components/lib/selectbutton/SelectButton.d.ts b/components/lib/selectbutton/SelectButton.d.ts index 3269cd3d53..e8c1a6369b 100755 --- a/components/lib/selectbutton/SelectButton.d.ts +++ b/components/lib/selectbutton/SelectButton.d.ts @@ -155,10 +155,16 @@ export interface SelectButtonProps { */ dataKey?: string | undefined; /** - * Whether selection can be cleared. + * Whether selection can not be cleared. * @defaultValue false + * @deprecated Use 'allowEmpty' property instead. */ unselectable?: boolean | undefined; + /** + * Whether selection can be cleared. + * @defaultValue true + */ + allowEmpty?: boolean | undefined; /** * Identifier of the underlying element. */ diff --git a/components/lib/selectbutton/SelectButton.vue b/components/lib/selectbutton/SelectButton.vue index a291fb572a..08ea3fc7bd 100755 --- a/components/lib/selectbutton/SelectButton.vue +++ b/components/lib/selectbutton/SelectButton.vue @@ -81,7 +81,7 @@ export default { let selected = this.isSelected(option); - if (selected && this.unselectable) { + if (selected && (this.unselectable || !this.allowEmpty)) { return; } diff --git a/doc/common/apidoc/index.json b/doc/common/apidoc/index.json index cb9026aaa7..310908af6c 100644 --- a/doc/common/apidoc/index.json +++ b/doc/common/apidoc/index.json @@ -42662,6 +42662,15 @@ "readonly": false, "type": "boolean", "default": "false", + "description": "Whether selection can not be cleared.", + "deprecated": "Use 'allowEmpty' property instead." + }, + { + "name": "allowEmpty", + "optional": true, + "readonly": false, + "type": "boolean", + "default": "true", "description": "Whether selection can be cleared." }, {