Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: update Checkbox to use accessibleName properties #6808

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -94,8 +93,6 @@ public class Checkbox extends AbstractSinglePropertyField<Checkbox, Boolean>

private static final PropertyChangeListener NO_OP = event -> {
};
private String ariaLabel;
private String ariaLabelledBy;

private CheckboxI18n i18n;

Expand Down Expand Up @@ -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<String> 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<String> 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"));
}

/**
Expand Down