Skip to content

Commit 2679322

Browse files
web-padawanclaude
andauthored
refactor: update Card to use HasAriaRole interface (#9590)
## Description Part of #9489 ## Type of change - Refactor Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 9bec658 commit 2679322

2 files changed

Lines changed: 6 additions & 42 deletions

File tree

  • vaadin-card-flow-parent/vaadin-card-flow/src

vaadin-card-flow-parent/vaadin-card-flow/src/main/java/com/vaadin/flow/component/card/Card.java

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import com.vaadin.flow.component.Component;
2424
import com.vaadin.flow.component.HasAriaLabel;
25+
import com.vaadin.flow.component.HasAriaRole;
2526
import com.vaadin.flow.component.HasComponents;
2627
import com.vaadin.flow.component.HasSize;
2728
import com.vaadin.flow.component.Tag;
@@ -40,8 +41,8 @@
4041
@Tag("vaadin-card")
4142
@NpmPackage(value = "@vaadin/card", version = "25.2.0")
4243
@JsModule("@vaadin/card/src/vaadin-card.js")
43-
public class Card extends Component implements HasSize,
44-
HasThemeVariant<CardVariant>, HasComponents, HasAriaLabel {
44+
public class Card extends Component implements HasSize, HasAriaLabel,
45+
HasAriaRole, HasComponents, HasThemeVariant<CardVariant> {
4546

4647
private static final String MEDIA_SLOT_NAME = "media";
4748
private static final String TITLE_SLOT_NAME = "title";
@@ -340,29 +341,6 @@ public void addComponentAtIndex(int index, Component component) {
340341
}
341342
}
342343

343-
/**
344-
* Sets the ARIA role attribute on the card.
345-
*
346-
* @param role
347-
* the ARIA role, or {@code null} to clear
348-
*/
349-
public void setAriaRole(String role) {
350-
if (role == null) {
351-
getElement().removeAttribute("role");
352-
} else {
353-
getElement().setAttribute("role", role);
354-
}
355-
}
356-
357-
/**
358-
* Gets the ARIA role attribute of the card.
359-
*
360-
* @return an optional ARIA role of the card if no ARIA role has been set
361-
*/
362-
public Optional<String> getAriaRole() {
363-
return Optional.ofNullable(getElement().getAttribute("role"));
364-
}
365-
366344
private void doSetTitle(String title) {
367345
if (title == null) {
368346
getElement().removeProperty(CARD_TITLE_PROPERTY);

vaadin-card-flow-parent/vaadin-card-flow/src/test/java/com/vaadin/flow/component/card/CardTest.java

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.junit.jupiter.api.extension.RegisterExtension;
2626

2727
import com.vaadin.flow.component.Component;
28+
import com.vaadin.flow.component.HasAriaRole;
2829
import com.vaadin.flow.component.html.Div;
2930
import com.vaadin.flow.component.html.Span;
3031
import com.vaadin.flow.component.shared.HasThemeVariant;
@@ -433,23 +434,8 @@ void addComponentAtIndex_withAlreadyAddedComponent() {
433434
}
434435

435436
@Test
436-
void ariaRoleEmptyByDefault() {
437-
Assertions.assertTrue(card.getAriaRole().isEmpty());
438-
}
439-
440-
@Test
441-
void setAriaRole_ariaRoleUpdated() {
442-
var ariaRole = "custom-role";
443-
card.setAriaRole(ariaRole);
444-
Assertions.assertTrue(card.getAriaRole().isPresent());
445-
Assertions.assertEquals(ariaRole, card.getAriaRole().get());
446-
}
447-
448-
@Test
449-
void setAriaRoleNull_ariaRoleUpdated() {
450-
card.setAriaRole("custom-role");
451-
card.setAriaRole(null);
452-
Assertions.assertTrue(card.getAriaRole().isEmpty());
437+
void implementsHasAriaRole() {
438+
Assertions.assertTrue(HasAriaRole.class.isAssignableFrom(Card.class));
453439
}
454440

455441
@Test

0 commit comments

Comments
 (0)