Skip to content

Commit 9152d83

Browse files
authored
fix: ensure Dialog has the data-rac attribute (#7189)
* Ensure `Dialog` has the `data-rac` attribute * cleanup
1 parent 06cdad7 commit 9152d83

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212
import {AriaDialogProps, useDialog, useId, useOverlayTrigger} from 'react-aria';
13-
import {ContextValue, DEFAULT_SLOT, Provider, SlotProps, StyleProps, useContextProps} from './utils';
13+
import {ContextValue, DEFAULT_SLOT, Provider, SlotProps, StyleProps, useContextProps, useRenderProps} from './utils';
1414
import {filterDOMProps} from '@react-aria/utils';
1515
import {forwardRefType} from '@react-types/shared';
1616
import {HeadingContext} from './RSPContexts';
@@ -76,13 +76,6 @@ function Dialog(props: DialogProps, ref: ForwardedRef<HTMLElement>) {
7676
}, ref);
7777
let state = useContext(OverlayTriggerStateContext);
7878

79-
let children = props.children;
80-
if (typeof children === 'function') {
81-
children = children({
82-
close: state?.close || (() => {})
83-
});
84-
}
85-
8679
if (!dialogProps['aria-label'] && !dialogProps['aria-labelledby']) {
8780
// If aria-labelledby exists on props, we know it came from context.
8881
// Use that as a fallback in case there is no title slot.
@@ -93,14 +86,23 @@ function Dialog(props: DialogProps, ref: ForwardedRef<HTMLElement>) {
9386
}
9487
}
9588

89+
let renderProps = useRenderProps({
90+
defaultClassName: 'react-aria-Dialog',
91+
className: props.className,
92+
style: props.style,
93+
children: props.children,
94+
values: {
95+
close: state?.close || (() => {})
96+
}
97+
});
98+
9699
return (
97100
<section
98101
{...filterDOMProps(props)}
99102
{...dialogProps}
103+
{...renderProps}
100104
ref={ref}
101-
slot={props.slot || undefined}
102-
style={props.style}
103-
className={props.className ?? 'react-aria-Dialog'}>
105+
slot={props.slot || undefined}>
104106
<Provider
105107
values={[
106108
[HeadingContext, {
@@ -110,7 +112,7 @@ function Dialog(props: DialogProps, ref: ForwardedRef<HTMLElement>) {
110112
}
111113
}]
112114
]}>
113-
{children}
115+
{renderProps.children}
114116
</Provider>
115117
</section>
116118
);

packages/react-aria-components/test/Dialog.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ describe('Dialog', () => {
3030
user = userEvent.setup({delay: null, pointerMap});
3131
});
3232

33+
it('should have a base default set of attributes', () => {
34+
let {getByRole} = render(
35+
<Dialog>
36+
<Heading slot="title">Title</Heading>
37+
</Dialog>
38+
);
39+
40+
let dialog = getByRole('dialog');
41+
expect(dialog).toHaveClass('react-aria-Dialog');
42+
expect(dialog).toHaveAttribute('data-rac');
43+
});
44+
3345
it('works with modal', async () => {
3446
let {getByRole} = render(
3547
<DialogTrigger>
@@ -155,6 +167,7 @@ describe('Dialog', () => {
155167
let heading = getByRole('heading');
156168
expect(dialog).toHaveAttribute('aria-labelledby', heading.id);
157169
expect(dialog).toHaveAttribute('data-test', 'dialog');
170+
expect(dialog).toHaveClass('react-aria-Dialog');
158171

159172
let popover = dialog.closest('.react-aria-Popover');
160173
expect(popover).toHaveStyle('position: absolute');

0 commit comments

Comments
 (0)