Skip to content

Commit 7c830d7

Browse files
authored
fix: pass aria labeling props in RAC Separator (#7881)
* fix: pass aria labeling props to useSeparator * add tests * fix lint * remove extra line
1 parent 51c0293 commit 7c830d7

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

packages/react-aria-components/src/Separator.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ export const SeparatorContext = createContext<ContextValue<SeparatorProps, HTMLE
2323
export const Separator = /*#__PURE__*/ createLeafComponent('separator', function Separator(props: SeparatorProps, ref: ForwardedRef<HTMLElement>) {
2424
[props, ref] = useContextProps(props, ref, SeparatorContext);
2525

26-
let {elementType, orientation, style, className} = props;
26+
let {elementType, orientation, style, className, slot, ...otherProps} = props;
2727
let Element = (elementType as ElementType) || 'hr';
2828
if (Element === 'hr' && orientation === 'vertical') {
2929
Element = 'div';
3030
}
3131

3232
let {separatorProps} = useSeparator({
33+
...otherProps,
3334
elementType,
3435
orientation
3536
});
@@ -41,6 +42,6 @@ export const Separator = /*#__PURE__*/ createLeafComponent('separator', function
4142
style={style}
4243
className={className ?? 'react-aria-Separator'}
4344
ref={ref}
44-
slot={props.slot || undefined} />
45+
slot={slot || undefined} />
4546
);
4647
});
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2025 Adobe. All rights reserved.
3+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License. You may obtain a copy
5+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under
8+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
* OF ANY KIND, either express or implied. See the License for the specific language
10+
* governing permissions and limitations under the License.
11+
*/
12+
13+
import React from 'react';
14+
import {render} from '@react-spectrum/test-utils-internal';
15+
import {Separator, SeparatorContext} from '../';
16+
17+
describe('Separator', () => {
18+
it('should render a separator with default class', () => {
19+
let {getByRole} = render(<Separator />);
20+
let separator = getByRole('separator');
21+
expect(separator.tagName).toBe('HR');
22+
expect(separator).toHaveAttribute('class', 'react-aria-Separator');
23+
});
24+
25+
it('should render a separator with custom class', () => {
26+
let {getByRole} = render(<Separator className="test" />);
27+
let separator = getByRole('separator');
28+
expect(separator).toHaveAttribute('class', 'test');
29+
});
30+
31+
it('should support DOM props', () => {
32+
let {getByRole} = render(<Separator data-foo="bar" />);
33+
let separator = getByRole('separator');
34+
expect(separator).toHaveAttribute('data-foo', 'bar');
35+
});
36+
37+
it('should support slot', () => {
38+
let {getByRole} = render(
39+
<SeparatorContext.Provider value={{slots: {test: {'aria-label': 'test'}}}}>
40+
<Separator slot="test" />
41+
</SeparatorContext.Provider>
42+
);
43+
44+
let separator = getByRole('separator');
45+
expect(separator).toHaveAttribute('slot', 'test');
46+
expect(separator).toHaveAttribute('aria-label', 'test');
47+
});
48+
49+
it('should support accessibility props', () => {
50+
let {getByRole} = render(<Separator aria-label="label" />);
51+
let separator = getByRole('separator');
52+
expect(separator).toHaveAttribute('aria-label', 'label');
53+
});
54+
});

0 commit comments

Comments
 (0)