-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
getOverflowAncestors.test.ts
67 lines (55 loc) · 2.18 KB
/
getOverflowAncestors.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import {getOverflowAncestors} from '../dom/src';
test('returns all overflow ancestors', () => {
const overflowScroll = document.createElement('div');
overflowScroll.style.overflow = 'scroll';
const overflowHidden = document.createElement('div');
overflowHidden.style.overflow = 'hidden';
const test = document.createElement('div');
overflowScroll.append(overflowHidden);
overflowHidden.append(test);
expect(getOverflowAncestors(test)).toEqual([
overflowHidden,
overflowScroll,
window,
]);
});
test('does not treat display: inline elements as overflow ancestors', () => {
const overflowScroll = document.createElement('div');
overflowScroll.style.overflow = 'scroll';
overflowScroll.style.display = 'inline';
const overflowHidden = document.createElement('div');
overflowHidden.style.overflow = 'hidden';
overflowHidden.style.display = 'inline';
const test = document.createElement('div');
overflowScroll.append(overflowHidden);
overflowHidden.append(test);
expect(getOverflowAncestors(test)).toEqual([window]);
});
test('does not treat display: contents elements as overflow ancestors', () => {
const overflowScroll = document.createElement('div');
overflowScroll.style.overflow = 'scroll';
overflowScroll.style.display = 'contents';
const overflowHidden = document.createElement('div');
overflowHidden.style.overflow = 'hidden';
overflowHidden.style.display = 'contents';
const test = document.createElement('div');
overflowScroll.append(overflowHidden);
overflowHidden.append(test);
expect(getOverflowAncestors(test)).toEqual([window]);
});
test('does treat display: inline-block elements as overflow ancestors', () => {
const overflowScroll = document.createElement('div');
overflowScroll.style.overflow = 'scroll';
overflowScroll.style.display = 'inline-block';
const overflowHidden = document.createElement('div');
overflowHidden.style.overflow = 'hidden';
overflowHidden.style.display = 'inline-block';
const test = document.createElement('div');
overflowScroll.append(overflowHidden);
overflowHidden.append(test);
expect(getOverflowAncestors(test)).toEqual([
overflowHidden,
overflowScroll,
window,
]);
});