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: allow data-* and aria-* attributes #344

Merged
merged 2 commits into from
Mar 16, 2024
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
2 changes: 2 additions & 0 deletions src/Collapse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const Collapse = React.forwardRef<HTMLDivElement, CollapseProps>((props, ref) =>
defaultActiveKey,
onChange,
items,
...restProps
} = props;

const collapseClassName = classNames(prefixCls, className);
Expand Down Expand Up @@ -81,6 +82,7 @@ const Collapse = React.forwardRef<HTMLDivElement, CollapseProps>((props, ref) =>
className={collapseClassName}
style={style}
role={accordion ? 'tablist' : undefined}
{...restProps}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! Thank you, done

>
{mergedChildren}
</div>
Expand Down
28 changes: 22 additions & 6 deletions tests/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('collapse', () => {
expect(collapse.container.querySelectorAll('.rc-collapse-content')).toHaveLength(0);
});

it('should render custom arrow icon corrctly', () => {
it('should render custom arrow icon correctly', () => {
expect(collapse.container.querySelector('.rc-collapse-header')?.textContent).toContain(
'test>',
);
Expand Down Expand Up @@ -190,23 +190,22 @@ describe('collapse', () => {

describe('prop: headerClass', () => {
it('applies the passed headerClass to the header', () => {

const element = (
<Collapse onChange={onChange} >
<Panel header="collapse 1" key="1" headerClass='custom-class'>
<Collapse onChange={onChange}>
<Panel header="collapse 1" key="1" headerClass="custom-class">
first
</Panel>
</Collapse>
);

const {container} = render(element)
const { container } = render(element);
const header = container.querySelector('.rc-collapse-header');

expect(header.classList.contains('custom-class')).toBeTruthy();
});
});

it('shoule support extra whit number 0', () => {
it('should support extra whit number 0', () => {
const { container } = render(
<Collapse onChange={onChange} activeKey={0}>
<Panel header="collapse 0" key={0} extra={0}>
Expand Down Expand Up @@ -843,5 +842,22 @@ describe('collapse', () => {
expect(container.querySelectorAll('.custom-icon')).toHaveLength(1);
expect(container.querySelector('.custom-icon')?.innerHTML).toBe('p');
});

it('should support data- and aria- attributes', () => {
const { container } = render(
<Collapse
data-testid="1234"
aria-label="test"
items={[
{
label: 'title',
} as any,
]}
/>,
);

expect(container.querySelector('.rc-collapse')?.getAttribute('data-testid')).toBe('1234');
expect(container.querySelector('.rc-collapse')?.getAttribute('aria-label')).toBe('test');
});
});
});
Loading