Skip to content

Commit 0eef790

Browse files
committed
update vc-align to 2.4.5
1 parent 508bc33 commit 0eef790

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

components/vc-align/Align.jsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import PropTypes from '../_util/vue-types';
22
import { alignElement, alignPoint } from 'dom-align';
33
import addEventListener from '../_util/Dom/addEventListener';
4-
import { isWindow, buffer, isSamePoint } from './util';
4+
import { isWindow, buffer, isSamePoint, isSimilarValue, restoreFocus } from './util';
55
import { cloneElement } from '../_util/vnode.js';
66
import clonedeep from 'lodash/cloneDeep';
77
import { getSlot } from '../_util/props-util';
@@ -73,7 +73,7 @@ export default {
7373
if (
7474
!reAlign &&
7575
source &&
76-
(preRect.width !== sourceRect.width || preRect.height !== sourceRect.height)
76+
(!isSimilarValue(preRect.width, sourceRect.width) || !isSimilarValue(preRect.height, sourceRect.height))
7777
) {
7878
reAlign = true;
7979
}
@@ -121,11 +121,16 @@ export default {
121121
const element = getElement(target);
122122
const point = getPoint(target);
123123

124+
// IE lose focus after element realign
125+
// We should record activeElement and restore later
126+
const activeElement = document.activeElement;
127+
124128
if (element) {
125129
result = alignElement(source, element, align);
126130
} else if (point) {
127131
result = alignPoint(source, point, align);
128132
}
133+
restoreFocus(activeElement, source);
129134
this.aligned = true;
130135
this.$listeners.align && this.$listeners.align(source, result);
131136
}

components/vc-align/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
// based on vc-align 2.4.3
1+
// based on vc-align 2.4.5
22
import Align from './Align';
33
export default Align;

components/vc-align/util.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import contains from '../_util/Dom/contains';
12
export function buffer(fn, ms) {
23
let timer;
34

@@ -36,3 +37,19 @@ export function isSamePoint(prev, next) {
3637
export function isWindow(obj) {
3738
return obj && typeof obj === 'object' && obj.window === obj;
3839
}
40+
41+
export function isSimilarValue(val1, val2) {
42+
const int1 = Math.floor(val1);
43+
const int2 = Math.floor(val2);
44+
return Math.abs(int1 - int2) <= 1;
45+
}
46+
47+
export function restoreFocus(activeElement, container) {
48+
// Focus back if is in the container
49+
if (
50+
activeElement !== document.activeElement &&
51+
contains(container, activeElement)
52+
) {
53+
activeElement.focus();
54+
}
55+
}

0 commit comments

Comments
 (0)