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

Consider automatically connecting button label with aria-labelledby #2358

Open
Robbert opened this issue Aug 19, 2024 · 1 comment
Open

Consider automatically connecting button label with aria-labelledby #2358

Robbert opened this issue Aug 19, 2024 · 1 comment
Labels
component/button enhancement New feature or request

Comments

@Robbert
Copy link
Member

Robbert commented Aug 19, 2024

In React, om een icon button te maken, kun je het volgende doen:

export const IconButton = forwardRef(({ label, ...restProps }) => (
  <Button {...restProps} label={
    <span class"sr-only">{label}</span>
  } />
    <Icon>{children}></Icon>
  </Button>
);

Als Button automatisch in aria-labelledby zou verwijzen naar de span die sowieso al om de inhoud van de label property heen staat, dan kun je simpelweg het label hidden maken, terwijl het toegankelijk label blijft werken:

export const IconButton = forwardRef(({ label, ...restProps }) => (
  <Button {...restProps} label={
    <span hidden>{label}</span>
  } />
    <Icon>{children}></Icon>
  </Button>
);

De vraag is: zijn er nadelen aan deze aanpak?

Eén van de gevolgen is: zodra je label gebruikt, dan wordt aria-labelledby gebruikt, en dan verdwijnen de children uit de label.

@Robbert Robbert added enhancement New feature or request component/button labels Aug 19, 2024
@Robbert
Copy link
Member Author

Robbert commented Aug 19, 2024

@bddjong penny for your thoughts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/button enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant