From 5e4d9e5b12387aaf841902d0005d38a483f5fcb1 Mon Sep 17 00:00:00 2001 From: web-padawan Date: Mon, 11 Nov 2024 13:36:45 +0200 Subject: [PATCH] refactor: update Checkbox to use accessibleName properties --- .../flow/component/checkbox/Checkbox.java | 27 ++++--------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/vaadin-checkbox-flow-parent/vaadin-checkbox-flow/src/main/java/com/vaadin/flow/component/checkbox/Checkbox.java b/vaadin-checkbox-flow-parent/vaadin-checkbox-flow/src/main/java/com/vaadin/flow/component/checkbox/Checkbox.java index 885e43c88f0..64856d89e5e 100644 --- a/vaadin-checkbox-flow-parent/vaadin-checkbox-flow/src/main/java/com/vaadin/flow/component/checkbox/Checkbox.java +++ b/vaadin-checkbox-flow-parent/vaadin-checkbox-flow/src/main/java/com/vaadin/flow/component/checkbox/Checkbox.java @@ -41,7 +41,6 @@ import com.vaadin.flow.data.binder.Binder; import com.vaadin.flow.data.binder.HasValidator; import com.vaadin.flow.data.binder.Validator; -import com.vaadin.flow.dom.ElementConstants; import com.vaadin.flow.dom.PropertyChangeListener; /** @@ -94,8 +93,6 @@ public class Checkbox extends AbstractSinglePropertyField private static final PropertyChangeListener NO_OP = event -> { }; - private String ariaLabel; - private String ariaLabelledBy; private CheckboxI18n i18n; @@ -307,37 +304,23 @@ public void setLabelComponent(Component component) { @Override public void setAriaLabel(String ariaLabel) { - toggleInputElementAttribute(ElementConstants.ARIA_LABEL_ATTRIBUTE_NAME, - ariaLabel); - this.ariaLabel = ariaLabel; + getElement().setProperty("accessibleName", ariaLabel); } @Override public Optional getAriaLabel() { - return Optional.ofNullable(ariaLabel); + return Optional.ofNullable(getElement().getProperty("accessibleName")); } @Override public void setAriaLabelledBy(String ariaLabelledBy) { - toggleInputElementAttribute( - ElementConstants.ARIA_LABELLEDBY_ATTRIBUTE_NAME, - ariaLabelledBy); - this.ariaLabelledBy = ariaLabelledBy; + getElement().setProperty("accessibleNameRef", ariaLabelledBy); } @Override public Optional getAriaLabelledBy() { - return Optional.ofNullable(ariaLabelledBy); - } - - private void toggleInputElementAttribute(String attribute, String value) { - if (value != null) { - getElement().executeJs("this.inputElement.setAttribute($0, $1)", - attribute, value); - } else { - getElement().executeJs("this.inputElement.removeAttribute($0)", - attribute); - } + return Optional + .ofNullable(getElement().getProperty("accessibleNameRef")); } /**