Skip to content

Commit 7d83de3

Browse files
committed
fixup! fixup! fixup! Add controlled popover
1 parent af6f18a commit 7d83de3

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

src/components/Popover/Popover.module.scss

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
// 1. Reset positioning for controlled variant.
2-
// 2. Shift Popover so there is space for the arrow between Popover and reference element.
3-
// 3. Add top offset in case it's not defined by external library.
1+
// 1. Hide the popover by default. This is needed because the popover is
2+
// controlled via CSS with the help of the helper popover. The popover can't
3+
// be displayed directly, because relative positioning doesn't work with
4+
// elements on the top-layer, so this CSS hack is needed.
5+
// 2. Hide the popover helper element.
6+
// 3. If the popover helper is open, show the actual popover.
7+
// 4. Reset positioning for controlled variant.
8+
// 5. Shift Popover so there is space for the arrow between Popover and reference element.
9+
// 6. Add top offset in case it's not defined by external library.
410

511
@use "theme";
612

@@ -49,20 +55,13 @@
4955
}
5056
}
5157

52-
/**
53-
* Controlled popover
54-
* Hide the popover by default. This is needed because the popover is
55-
* controlled via CSS with the help of the helper popover. The popover can't
56-
* be displayed directly, because relative positioning doesn't work with
57-
* elements on the top-layer, so this CSS hack is needed.
58-
*/
58+
// Controlled popover
5959
.controlledPopover {
60-
display: none;
60+
display: none; // 1.
6161
}
6262

63-
// Hide the popover helper element
6463
.helper {
65-
position: fixed;
64+
position: fixed; // 2.
6665
inset: unset;
6766
top: 0;
6867
right: 0;
@@ -74,9 +73,8 @@
7473
pointer-events: none;
7574
}
7675

77-
// If the popover helper is open, show the actual popover
7876
.helper:popover-open ~ .controlledPopover {
79-
display: block;
77+
display: block; // 3.
8078
}
8179

8280
// Sides
@@ -242,27 +240,27 @@
242240
.isRootControlled.isRootAtBottom,
243241
.isRootControlled.isRootAtLeft,
244242
.isRootControlled.isRootAtRight {
245-
inset: unset; // 1.
243+
inset: unset; // 4.
246244
}
247245

248246
.isRootControlled.isRootAtTop {
249-
transform: translate(0, calc(-1 * #{theme.$arrow-height})); // 2.
247+
transform: translate(0, calc(-1 * #{theme.$arrow-height})); // 5.
250248
}
251249

252250
.isRootControlled.isRootAtBottom {
253-
transform: translate(0, #{theme.$arrow-height}); // 2.
251+
transform: translate(0, #{theme.$arrow-height}); // 5.
254252
}
255253

256254
.isRootControlled.isRootAtLeft {
257-
transform: translate(calc(-1 * #{theme.$arrow-height}), 0); // 2.
255+
transform: translate(calc(-1 * #{theme.$arrow-height}), 0); // 5.
258256
}
259257

260258
.isRootControlled.isRootAtRight {
261-
transform: translate(#{theme.$arrow-height}, 0); // 2.
259+
transform: translate(#{theme.$arrow-height}, 0); // 5.
262260
}
263261

264262
.isRootControlled.isRootAtLeft.isRootAtStart,
265263
.isRootControlled.isRootAtRight.isRootAtStart {
266-
top: 0; // 3.
264+
top: 0; // 6.
267265
}
268266
}

0 commit comments

Comments
 (0)