Skip to content
Merged
Show file tree
Hide file tree
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 @@ -18,6 +18,7 @@
import java.util.Optional;

import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.HasAriaRole;
import com.vaadin.flow.component.HasSize;
import com.vaadin.flow.component.HasText;
import com.vaadin.flow.component.SignalPropertySupport;
Expand Down Expand Up @@ -67,8 +68,8 @@
@Tag("vaadin-badge")
@NpmPackage(value = "@vaadin/badge", version = "25.2.0")
@JsModule("@vaadin/badge/src/vaadin-badge.js")
public class Badge extends Component
implements HasSize, HasText, HasThemeVariant<BadgeVariant> {
public class Badge extends Component implements HasAriaRole, HasSize, HasText,
HasThemeVariant<BadgeVariant> {

private static final String ICON_SLOT = "icon";

Expand Down Expand Up @@ -309,22 +310,22 @@ public Component getIcon() {
*
* @param role
* the ARIA role, or {@code null} to clear
* @deprecated Use {@link #setAriaRole(String)} instead.
*/
@Deprecated(since = "25.3", forRemoval = true)
public void setRole(String role) {
if (role == null) {
getElement().removeAttribute("role");
} else {
getElement().setAttribute("role", role);
}
setAriaRole(role);
}

/**
* Gets the ARIA role attribute of the badge.
*
* @return the ARIA role, or {@code null} if not set
* @deprecated Use {@link #getAriaRole()} instead.
*/
@Deprecated(since = "25.3", forRemoval = true)
public String getRole() {
return getElement().getAttribute("role");
return getAriaRole().orElse(null);
}

private void updateText(String text) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import com.vaadin.flow.component.HasAriaRole;
import com.vaadin.flow.component.badge.Badge;
import com.vaadin.flow.component.html.Span;

Expand Down Expand Up @@ -183,6 +184,7 @@ void getContent_doesNotReturnTextOrIcon() {
}

@Test
@SuppressWarnings("deprecation")
void setRole_getRole() {
var badge = new Badge();
Assertions.assertNull(badge.getRole());
Expand All @@ -194,6 +196,11 @@ void setRole_getRole() {
Assertions.assertNull(badge.getRole());
}

@Test
void implementsHasAriaRole() {
Assertions.assertTrue(HasAriaRole.class.isAssignableFrom(Badge.class));
}

@Test
void setIcon_getIcon() {
var badge = new Badge();
Expand Down
Loading