Skip to content

Commit

Permalink
use rc-utils
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Feb 14, 2019
1 parent f4a0852 commit ad56a1d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
4 changes: 1 addition & 3 deletions src/Align.jsx
Expand Up @@ -143,9 +143,7 @@ class Align extends Component {
result = alignPoint(source, point, align);
}

if (activeElement && activeElement !== document.activeElement) {
restoreFocus(activeElement, source);
}
restoreFocus(activeElement, source);

if (onAlign) {
onAlign(source, result);
Expand Down
12 changes: 5 additions & 7 deletions src/util.js
@@ -1,3 +1,5 @@
import contains from 'rc-util/lib/Dom/contains';

export function buffer(fn, ms) {
let timer;

Expand Down Expand Up @@ -44,16 +46,12 @@ export function isSimilarValue(val1, val2) {
}

export function restoreFocus(activeElement, container) {
let currentElement = activeElement;
while (currentElement) {
if (currentElement === container) {
break;
}
currentElement = currentElement.parentNode;
if (!activeElement || activeElement === document.activeElement) {
return;
}

// Focus back if is in the container
if (currentElement) {
if (contains(container, activeElement)) {
activeElement.focus();
}
}

0 comments on commit ad56a1d

Please sign in to comment.