Skip to content

TagGroup doesn't add role attr when collection is emptyΒ #8354

Open
@mauron85

Description

@mauron85

Provide a general summary of the issue here

When the TagGroup collection is empty, it still renders a <div> element with ARIA-related attributes, but the role attribute is missing. This results in a DOM node with ARIA attributes applied to an element that lacks a valid role, which violates accessibility best practices as outlined in ARIA prohibited attributes.

The problematic logic appears to be in the useTagGroup hook:
https://github.com/adobe/react-spectrum/blob/4150364a2dfa249ca149723548c62e0d3325476f/packages/%40react-aria/tag/src/useTagGroup.ts#L108C19-L108C29

πŸ€” Expected Behavior?

If no role is added to tag group element div then don't add other aria attributes aswell or keep role attribute grid even when collection is empty.

😯 Current Behavior

When TagGroup collection is empty it creates div with all aria attributtes but role is absent.

πŸ’ Possible Solution

  1. don't add other aria attributes when role is not set
    or
  2. keep role attribute grid even when collection is empty.

πŸ”¦ Context

We are checking our application using browserstack accesibility toolkit and it's giving us errors because of TagGroup role issue.

πŸ–₯️ Steps to Reproduce

  1. Create TagGroup with no Tags
  2. Observe generated dom element for TagGroup - missing role with there are not Tags

Version

react-aria: 3.40.0, react-aria-components: 1.9.0

What browsers are you seeing the problem on?

Chrome

If other, please specify.

No response

What operating system are you using?

Windows

🧒 Your Company/Team

No response

πŸ•· Tracking Issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions