Skip to content

Commit 9907ac9

Browse files
authored
fix: remove autoFocus attr on dom (#202)
1 parent aef7287 commit 9907ac9

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

src/DrawerChild.tsx

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,8 @@ class DrawerChild extends React.Component<IDrawerChildProps, IState> {
119119
}
120120

121121
public componentDidUpdate(prevProps: IDrawerChildProps) {
122-
const {
123-
open,
124-
getContainer,
125-
scrollLocker,
126-
showMask,
127-
autoFocus,
128-
} = this.props;
122+
const { open, getContainer, scrollLocker, showMask, autoFocus } =
123+
this.props;
129124
const container = getContainer && getContainer();
130125
if (open !== prevProps.open) {
131126
if (container && container.parentNode === document.body) {
@@ -232,10 +227,8 @@ class DrawerChild extends React.Component<IDrawerChildProps, IState> {
232227

233228
private openLevelTransition = () => {
234229
const { open, width, height } = this.props;
235-
const {
236-
isHorizontal,
237-
placementName,
238-
} = this.getHorizontalBoolAndPlacementName();
230+
const { isHorizontal, placementName } =
231+
this.getHorizontalBoolAndPlacementName();
239232
const contentValue = this.contentDom
240233
? this.contentDom.getBoundingClientRect()[
241234
isHorizontal ? 'width' : 'height'
@@ -530,7 +523,7 @@ class DrawerChild extends React.Component<IDrawerChildProps, IState> {
530523
});
531524
return (
532525
<div
533-
{...omit(props, ['switchScrollingEffect'])}
526+
{...omit(props, ['switchScrollingEffect', 'autoFocus'])}
534527
tabIndex={-1}
535528
className={wrapperClassName}
536529
style={style}
@@ -567,7 +560,7 @@ class DrawerChild extends React.Component<IDrawerChildProps, IState> {
567560
className={`${prefixCls}-content`}
568561
ref={c => {
569562
this.contentDom = c as HTMLElement;
570-
}}
563+
}}
571564
>
572565
{children}
573566
</div>

tests/index.spec.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,9 @@ describe('rc-drawer-menu', () => {
243243
instance.find('.auto-focus-test-wrapper .drawer').at(0).getDOMNode(),
244244
);
245245

246+
// autofocus should not treat as dom attribute when {autofocus: false}
247+
expect(instance.html().indexOf('autofocus')).toBe(-1);
248+
246249
// Close and reopen drawer with props {autoFocus: true}
247250
instance.setProps({ open: false, autoFocus: true });
248251

@@ -252,5 +255,8 @@ describe('rc-drawer-menu', () => {
252255
expect(document.activeElement).toBe(
253256
instance.find('.auto-focus-test-wrapper .drawer').at(0).getDOMNode(),
254257
);
258+
259+
// autofocus should not treat as dom attribute when {autofocus: true}
260+
expect(instance.html().indexOf('autofocus')).toBe(-1);
255261
});
256262
});

0 commit comments

Comments
 (0)