Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/Dialog/Mask.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type MaskProps = {
motionName?: string;
style?: React.CSSProperties;
maskProps?: React.HTMLAttributes<HTMLDivElement>;
}
};

export default function Mask(props: MaskProps) {
const { prefixCls, style, visible, maskProps, motionName } = props;
Expand Down
6 changes: 5 additions & 1 deletion src/Dialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default function Dialog(props: IDialogChildProps) {
maskClosable = true,
maskStyle,
maskProps,
rootClassName,
} = props;

const lastOutSideActiveElementRef = useRef<HTMLElement>();
Expand Down Expand Up @@ -163,7 +164,10 @@ export default function Dialog(props: IDialogChildProps) {

// ========================= Render =========================
return (
<div className={`${prefixCls}-root`} {...pickAttrs(props, { data: true })}>
<div
className={classNames(`${prefixCls}-root`, rootClassName)}
{...pickAttrs(props, { data: true })}
>
<Mask
prefixCls={prefixCls}
visible={mask && visible}
Expand Down
1 change: 1 addition & 0 deletions src/IDialogPropTypes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export type IDialogPropTypes = {
zIndex?: number;
bodyProps?: any;
maskProps?: any;
rootClassName?: string;
wrapProps?: any;
getContainer?: GetContainer | false;
closeIcon?: ReactNode;
Expand Down
97 changes: 97 additions & 0 deletions tests/__snapshots__/index.spec.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`dialog add rootClassName should render correct 1`] = `
<div
class="rc-dialog-root customize-root-class"
>
<div
class="rc-dialog-mask"
/>
<div
class="rc-dialog-wrap"
role="dialog"
style="font-size: 10px;"
tabindex="-1"
>
<div
class="rc-dialog"
role="document"
style="width: 600px; height: 903px;"
>
<div
aria-hidden="true"
style="width: 0px; height: 0px; overflow: hidden; outline: none;"
tabindex="0"
/>
<div
class="rc-dialog-content"
>
<button
aria-label="Close"
class="rc-dialog-close"
type="button"
>
<span
class="rc-dialog-close-x"
/>
</button>
<div
class="rc-dialog-body"
/>
</div>
<div
aria-hidden="true"
style="width: 0px; height: 0px; overflow: hidden; outline: none;"
tabindex="0"
/>
</div>
</div>
</div>
`;

exports[`dialog should render correct 1`] = `
<div
class="rc-dialog-root"
>
<div
class="rc-dialog-mask"
/>
<div
class="rc-dialog-wrap"
role="dialog"
tabindex="-1"
>
<div
class="rc-dialog"
role="document"
>
<div
aria-hidden="true"
style="width: 0px; height: 0px; overflow: hidden; outline: none;"
tabindex="0"
/>
<div
class="rc-dialog-content"
>
<button
aria-label="Close"
class="rc-dialog-close"
type="button"
>
<span
class="rc-dialog-close-x"
/>
</button>
<div
class="rc-dialog-body"
/>
</div>
<div
aria-hidden="true"
style="width: 0px; height: 0px; overflow: hidden; outline: none;"
tabindex="0"
/>
</div>
</div>
</div>
`;
38 changes: 33 additions & 5 deletions tests/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,34 @@ describe('dialog', () => {
jest.useRealTimers();
});

it('should render correct', () => {
const wrapper = mount(<Dialog visible />);
jest.runAllTimers();
wrapper.update();

expect(wrapper.render()).toMatchSnapshot();
});

it('add rootClassName should render correct', () => {
const wrapper = mount(
<Dialog
visible
rootClassName="customize-root-class"
style={{ width: 600 }}
height={903}
wrapStyle={{ fontSize: 10 }}
/>,
);
jest.runAllTimers();
wrapper.update();

expect(wrapper.render()).toMatchSnapshot();
expect(wrapper.find('.customize-root-class').length).toBeTruthy();
expect(wrapper.find('.rc-dialog-wrap').props().style.fontSize).toBe(10);
expect(wrapper.find('.rc-dialog').props().style.height).toEqual(903);
expect(wrapper.find('.rc-dialog').props().style.width).toEqual(600);
});

it('show', () => {
const wrapper = mount(<Dialog visible />);
jest.runAllTimers();
Expand Down Expand Up @@ -92,10 +120,10 @@ describe('dialog', () => {
jest.runAllTimers();
wrapper.update();

((document.getElementsByClassName('.test-input') as unknown) as HTMLInputElement).value =
(document.getElementsByClassName('.test-input') as unknown as HTMLInputElement).value =
'test';
expect(
((document.getElementsByClassName('.test-input') as unknown) as HTMLInputElement).value,
(document.getElementsByClassName('.test-input') as unknown as HTMLInputElement).value,
).toBe('test');

// Hide
Expand All @@ -109,7 +137,7 @@ describe('dialog', () => {
wrapper.update();

expect(
((document.getElementsByClassName('.test-input') as unknown) as HTMLInputElement).value,
(document.getElementsByClassName('.test-input') as unknown as HTMLInputElement).value,
).toBeUndefined();
wrapper.unmount();
});
Expand Down Expand Up @@ -208,9 +236,9 @@ describe('dialog', () => {
describe('Tab should keep focus in dialog', () => {
it('basic tabbing', () => {
const wrapper = mount(<Dialog visible />, { attachTo: document.body });
const sentinelEnd = (document.querySelectorAll(
const sentinelEnd = document.querySelectorAll(
'.rc-dialog-content + div',
)[0] as unknown) as HTMLDivElement;
)[0] as unknown as HTMLDivElement;
sentinelEnd.focus();

wrapper.find('.rc-dialog-wrap').simulate('keyDown', {
Expand Down