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: pass aria labeling props in RAC Separator #7881

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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: 3 additions & 2 deletions packages/react-aria-components/src/Separator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ export const SeparatorContext = createContext<ContextValue<SeparatorProps, HTMLE
export const Separator = /*#__PURE__*/ createLeafComponent('separator', function Separator(props: SeparatorProps, ref: ForwardedRef<HTMLElement>) {
[props, ref] = useContextProps(props, ref, SeparatorContext);

let {elementType, orientation, style, className} = props;
let {elementType, orientation, style, className, slot, ...otherProps} = props;
let Element = (elementType as ElementType) || 'hr';
if (Element === 'hr' && orientation === 'vertical') {
Element = 'div';
}

let {separatorProps} = useSeparator({
...otherProps,
elementType,
orientation
});
Expand All @@ -41,6 +42,6 @@ export const Separator = /*#__PURE__*/ createLeafComponent('separator', function
style={style}
className={className ?? 'react-aria-Separator'}
ref={ref}
slot={props.slot || undefined} />
slot={slot || undefined} />
);
});
54 changes: 54 additions & 0 deletions packages/react-aria-components/test/Separator.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2025 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

import React from 'react';
import {render} from '@react-spectrum/test-utils-internal';
import {Separator, SeparatorContext} from '../';

describe('Separator', () => {
it('should render a separator with default class', () => {
let {getByRole} = render(<Separator />);
let separator = getByRole('separator');
expect(separator.tagName).toBe('HR');
expect(separator).toHaveAttribute('class', 'react-aria-Separator');
});

it('should render a separator with custom class', () => {
let {getByRole} = render(<Separator className="test" />);
let separator = getByRole('separator');
expect(separator).toHaveAttribute('class', 'test');
});

it('should support DOM props', () => {
let {getByRole} = render(<Separator data-foo="bar" />);
let separator = getByRole('separator');
expect(separator).toHaveAttribute('data-foo', 'bar');
});

it('should support slot', () => {
let {getByRole} = render(
<SeparatorContext.Provider value={{slots: {test: {'aria-label': 'test'}}}}>
<Separator slot="test" />
</SeparatorContext.Provider>
);

let separator = getByRole('separator');
expect(separator).toHaveAttribute('slot', 'test');
expect(separator).toHaveAttribute('aria-label', 'test');
});

it('should support accessibility props', () => {
let {getByRole} = render(<Separator aria-label="label" />);
let separator = getByRole('separator');
expect(separator).toHaveAttribute('aria-label', 'label');
});
});