From 42a1326d5d3b08823aadf5f58876a82e151dfd4d Mon Sep 17 00:00:00 2001
From: Nayden Naydenov <31909318+nnaydenow@users.noreply.github.com>
Date: Fri, 28 May 2021 10:20:30 +0300
Subject: [PATCH] feat(ui5-checkbox): add indeterminate state (#3309)
Added new property attribute which determines whether the component is displayed as partially checked.
Fixes: #3217
---
packages/main/src/CheckBox.hbs | 4 +-
packages/main/src/CheckBox.js | 37 ++++++++-
packages/main/src/themes/CheckBox.css | 13 ++-
.../main/src/themes/base/sizes-parameters.css | 2 +
packages/main/test/pages/CheckBox.html | 6 ++
.../main/test/samples/CheckBox.sample.html | 80 +++++++++++++++++++
6 files changed, 135 insertions(+), 7 deletions(-)
diff --git a/packages/main/src/CheckBox.hbs b/packages/main/src/CheckBox.hbs
index 6998864e2800..6e0ef72ed754 100644
--- a/packages/main/src/CheckBox.hbs
+++ b/packages/main/src/CheckBox.hbs
@@ -1,7 +1,7 @@
- {{#if checked}}
+ {{#if isCompletelyChecked}}
{{/if}}
diff --git a/packages/main/src/CheckBox.js b/packages/main/src/CheckBox.js
index 0dc4619f26a4..b2af88428b73 100644
--- a/packages/main/src/CheckBox.js
+++ b/packages/main/src/CheckBox.js
@@ -56,6 +56,27 @@ const metadata = {
type: Boolean,
},
+ /**
+ * Defines whether the component is displayed as partially checked.
+ *
+ *
Note: The indeterminate state can be set only programatically and can’t be achieved by user
+ * interaction and the resulting visual state depends on the values of the
indeterminate
+ * and
checked
properties:
+ *
+ * - If the component is checked and indeterminate, it will be displayed as partially checked
+ *
- If the component is checked and it is not indeterminate, it will be displayed as checked
+ *
- If the component is not checked, it will be displayed as not checked regardless value of the indeterminate attribute
+ *
+ *
+ * @type {boolean}
+ * @defaultvalue false
+ * @public
+ * @since 1.0.0-rc.15
+ */
+ indeterminate: {
+ type: Boolean,
+ },
+
/**
* Defines if the component is checked.
*
@@ -307,7 +328,13 @@ class CheckBox extends UI5Element {
toggle() {
if (this.canToggle()) {
- this.checked = !this.checked;
+ if (this.indeterminate) {
+ this.indeterminate = false;
+ this.checked = true;
+ } else {
+ this.checked = !this.checked;
+ }
+
this.fireEvent("change");
// Angular two way data binding
this.fireEvent("value-changed");
@@ -349,6 +376,10 @@ class CheckBox extends UI5Element {
return getEffectiveAriaLabelText(this);
}
+ get ariaChecked() {
+ return this.indeterminate && this.checked ? "mixed" : this.checked;
+ }
+
get ariaLabelledBy() {
if (!this.ariaLabelText) {
return this.text ? `${this._id}-label` : undefined;
@@ -374,6 +405,10 @@ class CheckBox extends UI5Element {
return this.disabled ? undefined : tabindex || "0";
}
+ get isCompletelyChecked() {
+ return this.checked && !this.indeterminate;
+ }
+
static get dependencies() {
return [
Label,
diff --git a/packages/main/src/themes/CheckBox.css b/packages/main/src/themes/CheckBox.css
index 3a911f28bda9..1e182402fe04 100644
--- a/packages/main/src/themes/CheckBox.css
+++ b/packages/main/src/themes/CheckBox.css
@@ -74,7 +74,8 @@
color: var(--sapField_SuccessColor);
}
-:host([value-state="Warning"]) .ui5-checkbox-icon {
+:host([value-state="Warning"]) .ui5-checkbox-icon,
+:host([value-state="Warning"][indeterminate]) .ui5-checkbox-inner::after {
color: var(--_ui5_checkbox_checkmark_warning_color);
}
@@ -142,9 +143,11 @@ https://github.com/philipwalton/flexbugs/issues/231
pointer-events: none;
}
-.ui5-checkbox-icon {
- color: currentColor;
- cursor: default;
+:host([indeterminate][checked]) .ui5-checkbox-inner::after {
+ content: "";
+ background-color: currentColor;
+ width: var(--_ui5_checkbox_partially_icon_size);
+ height: var(--_ui5_checkbox_partially_icon_size);
}
.ui5-checkbox-inner input {
@@ -170,6 +173,8 @@ https://github.com/philipwalton/flexbugs/issues/231
.ui5-checkbox-icon {
width: var(--_ui5_checkbox_icon_size);
height: var(--_ui5_checkbox_icon_size);
+ color: currentColor;
+ cursor: default;
}
/* RTL */
diff --git a/packages/main/src/themes/base/sizes-parameters.css b/packages/main/src/themes/base/sizes-parameters.css
index e042e823f20d..372d0f247f95 100644
--- a/packages/main/src/themes/base/sizes-parameters.css
+++ b/packages/main/src/themes/base/sizes-parameters.css
@@ -9,6 +9,7 @@
--_ui5_checkbox_root_side_padding: .6875rem;
--_ui5_checkbox_icon_size: 1rem;
+ --_ui5_checkbox_partially_icon_size: .75rem;
--_ui5_custom_list_item_height: 3rem;
--_ui5_custom_list_item_rb_min_width: 2.75rem;
--_ui5_day_picker_item_width: 2.25rem;
@@ -116,6 +117,7 @@
--_ui5_checkbox_focus_position: var(--_ui5_checkbox_compact_focus_position);
--_ui5_checkbox_inner_width_height: var(--_ui5_checkbox_compact_inner_size);
--_ui5_checkbox_icon_size: .75rem;
+ --_ui5_checkbox_partially_icon_size: .5rem;
/* ColorPalette */
--_ui5_color-palette-item-height: 1.25rem;
diff --git a/packages/main/test/pages/CheckBox.html b/packages/main/test/pages/CheckBox.html
index 2e6f6099a9d2..8abca895d79a 100644
--- a/packages/main/test/pages/CheckBox.html
+++ b/packages/main/test/pages/CheckBox.html
@@ -35,6 +35,12 @@
ACC test - aria-label
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+