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

fix: update accordion item heading tag to be customizable #2265

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions .changeset/heavy-hairs-join.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nextui-org/accordion": major
outputboy marked this conversation as resolved.
Show resolved Hide resolved
---

Make the accordion item heading tag customizable to satisfy a11y needs. Headings in web page needs to be consistent and semantic, this will help all users to better find the content they are looking for.
outputboy marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 3 additions & 2 deletions packages/components/accordion/src/accordion-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface AccordionItemProps extends UseAccordionItemProps {}
const AccordionItem = forwardRef<"button", AccordionItemProps>((props, ref) => {
const {
Component,
HeadingComponent,
classNames,
slots,
indicator,
Expand Down Expand Up @@ -85,7 +86,7 @@ const AccordionItem = forwardRef<"button", AccordionItemProps>((props, ref) => {

return (
<Component {...getBaseProps()}>
<h2 {...getHeadingProps()}>
<HeadingComponent {...getHeadingProps()}>
<button {...getButtonProps()}>
{startContent && (
<div className={slots.startContent({class: classNames?.startContent})}>
Expand All @@ -100,7 +101,7 @@ const AccordionItem = forwardRef<"button", AccordionItemProps>((props, ref) => {
<span {...getIndicatorProps()}>{indicatorComponent}</span>
)}
</button>
</h2>
</HeadingComponent>
{content}
</Component>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
SlotsToClasses,
} from "@nextui-org/theme";

import {As} from "@nextui-org/system";
import {ItemProps, BaseItem} from "@nextui-org/aria-utils";
import {FocusableProps, PressEvents} from "@react-types/shared";
import {ReactNode, MouseEventHandler} from "react";
Expand All @@ -24,7 +25,6 @@ export type AccordionItemIndicatorProps = {
*/
isDisabled?: boolean;
};

export interface Props<T extends object = {}>
extends Omit<ItemProps<"button", T>, "children" | "title" | keyof FocusableProps>,
FocusableProps,
Expand Down Expand Up @@ -85,6 +85,13 @@ export interface Props<T extends object = {}>
* ```
*/
classNames?: SlotsToClasses<AccordionItemSlots>;

/**
* Customizable heading tag for Web accessibility:
* use headings to describe content and use them consistently and semantically.
* This will help all users to better find the content they are looking for.
*/
HeadingComponent?: As;
}

export type AccordionItemBaseProps<T extends object = {}> = Props<T> & AccordionItemVariantProps;
Expand Down
2 changes: 2 additions & 0 deletions packages/components/accordion/src/use-accordion-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export function useAccordionItem<T extends object = {}>(props: UseAccordionItemP
disableAnimation = false,
keepContentMounted = false,
disableIndicatorAnimation = false,
HeadingComponent = as || "h2",
onPress,
onPressStart,
onPressEnd,
Expand Down Expand Up @@ -238,6 +239,7 @@ export function useAccordionItem<T extends object = {}>(props: UseAccordionItemP

return {
Component,
HeadingComponent,
item,
slots,
classNames,
Expand Down