fix(ui): center icon tooltips over their trigger (#11382)
This commit is contained in:
parent
81f3cc6446
commit
25df9ec473
2 changed files with 5 additions and 6 deletions
|
|
@ -38,11 +38,11 @@
|
|||
this.visible = true;
|
||||
const rect = target.getBoundingClientRect();
|
||||
this.below = rect.top < 48;
|
||||
this.x = rect.left;
|
||||
this.x = rect.left + rect.width / 2;
|
||||
this.y = this.below ? rect.bottom + 8 : rect.top - 8;
|
||||
this.$nextTick(() => {
|
||||
const width = this.$refs.tooltip?.offsetWidth || 0;
|
||||
this.x = Math.max(8, Math.min(window.innerWidth - width - 8, this.x));
|
||||
this.x = Math.max(8, Math.min(window.innerWidth - width - 8, this.x - width / 2));
|
||||
this.$nextTick(() => this.positioned = true);
|
||||
});
|
||||
},
|
||||
|
|
|
|||
|
|
@ -36,12 +36,11 @@
|
|||
->toContain("positioned ? 'visible' : 'invisible'");
|
||||
});
|
||||
|
||||
it('anchors tooltips to the trigger and lets them grow toward the right', function () {
|
||||
it('centers tooltips on the trigger and keeps them within the viewport', function () {
|
||||
$tooltip = file_get_contents(resource_path('views/components/icon-tooltip.blade.php'));
|
||||
|
||||
expect($tooltip)
|
||||
->toContain('this.x = rect.left;')
|
||||
->toContain('Math.min(window.innerWidth - width - 8, this.x)')
|
||||
->not->toContain('rect.left + rect.width / 2')
|
||||
->toContain('this.x = rect.left + rect.width / 2;')
|
||||
->toContain('Math.min(window.innerWidth - width - 8, this.x - width / 2)')
|
||||
->not->toContain('-translate-x-1/2');
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue