Skip to content

Proposal: Collapse accessibility enhancements #53203

Open

Description

@John-Feola

What problem does this feature solve?

The collapse component does not comply with w3c accessibility guidelines here: https://www.w3.org/WAI/ARIA/apg/patterns/accordion/

What does the proposed API look like?

Proposed Changes:

  1. Add an optional prop allowing user/consumer to set a heading level for the collapse button. We could use headingLevel?: h1 | h2 | h3 | h4 | h5 | h6, and then wrap the collapse-button-header in the <h_>.

  2. Set an aria-controls attribute on each button, and the aria-controls would reference the id of the panel that the button controls.

  3. Add an optional Collapse prop, panelsRole?: 'region' | 'none', by which consumers can optionally set role="region" on the panels.

These changes would have little impact on consumers implementation, but would improve accessibility by default, and also give consumers powerful opt-in functionality to set the heading level and role="region".

Please let me know if you find the proposed changes acceptable.

Activity

  1. petercat-assistant commented on Mar 18, 2025

    @petercat-assistant

    Thank you for your proposal to enhance the accessibility of the Collapse component in Ant Design. Your suggestions to align with the W3C accessibility guidelines are valuable. Here's a summary of your proposed changes:

    1. Heading Level Prop: Introduce an optional prop headingLevel to allow users to set a heading level for the collapse button, using options like h1 | h2 | h3 | h4 | h5 | h6. This would wrap the collapse-button-header in the corresponding <h_> tag.

    2. Aria-Controls Attribute: Implement an aria-controls attribute on each button, which would reference the ID of the panel that the button controls, enhancing accessibility.

    3. Panels Role Prop: Add an optional panelsRole prop, allowing consumers to set role="region" on the panels, with options 'region' | 'none'.

    These enhancements aim to improve accessibility by default while providing consumers with the flexibility to opt-in for additional functionality. I will note your proposal for consideration by the team.

    If you have any further questions or need additional assistance, feel free to ask.

    🪧 Tips For further assistance, please describe your question in the comments and @petercat-assistant to start a conversation with me.
  2. MadCcc commented on Mar 19, 2025

    @MadCcc
    Member
    1. Maybe components props for Collapse could be better, or it will be fixed by antd.
  3. added
    help wantedThe suggestion or request has been accepted, we need you to help us by sending a pull request.
    on Mar 19, 2025
  4. github-actions commented on Mar 19, 2025

    @github-actions
    Contributor

    Hello @John-Feola. We totally like your proposal/feedback, welcome to send us a Pull Request for it. Please send your Pull Request to proper branch (feature branch for the new feature, master for bugfix and other changes), fill the Pull Request Template here, provide changelog/TypeScript/documentation/test cases if needed and make sure CI passed, we will review it soon. We appreciate your effort in advance and looking forward to your contribution!

    你好 @John-Feola,我们完全同意你的提议/反馈,欢迎直接在此仓库 创建一个 Pull Request 来解决这个问题。请将 Pull Request 发到正确的分支(新特性发到 feature 分支,其他发到 master 分支),务必填写 Pull Request 内的预设模板,提供改动所需相应的 changelog、TypeScript 定义、测试用例、文档等,并确保 CI 通过,我们会尽快进行 Review,提前感谢和期待您的贡献。

    giphy

  5. mellis481 commented on Mar 19, 2025

    @mellis481
    Contributor
    1. Maybe components props for Collapse could be better.

    @MadCcc Can you provide some more information on what you are suggesting here please?

  6. jon-cullison commented on Mar 20, 2025

    @jon-cullison
    Contributor

    I will work on this issue.

  7. jon-cullison commented on Mar 25, 2025

    @jon-cullison
    Contributor

    @MadCcc
    I am making changes in react-component/collapse to implement the proposed accessibility improvements. However, while working on the 2nd change to link the header and panel content by id, I found that in the collapse component there currently are no default IDs being generated and applied to the subcomponents.

    In order to link the two elements without making consumers provide an ID to the Collapse component, I would like to include some default ID. I considered using the React.useId() hook, but that does not guarantee unique IDs when there are multiple react applications rendered at the same time. Another approach would be to use the uuid library to generate a default unique ID.

    Would using uuid be acceptable or is there another suggested approach to generating default IDs that are unique across multiple react applications?

  8. jon-cullison commented on Apr 10, 2025

    @jon-cullison
    Contributor

    I have made changes in react-component/collapse to implement the proposed accessibility improvements: react-component/collapse#363

    Note: I did not implement the panel role change because there is already some logic around setting the panel role to "tabpanel" when in accordion mode, and the panel role = "region" is optional for a11y purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Inactivehelp wantedThe suggestion or request has been accepted, we need you to help us by sending a pull request.⌨️ Accessibility

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions