Skip to content

Commit 5371c5b

Browse files
authored
fix(popover): prevent scrollbar (#2730)
* fix(popover): prevent scrollbar * style: update elements/pf-popover/pf-popover.ts
1 parent 67eb59c commit 5371c5b

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

.changeset/upset-laws-camp.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@patternfly/elements": patch
3+
---
4+
`<pf-popover>`: prevent appearance of an unwanted scrollbar in some cases where
5+
popover is positioned at the far edge of the viewport
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<p>
2+
When the viewport is <code>1190</code> pixels wide, (such that the "toggle popover" button appears
3+
at the far edge of the viewport, the popover at the far end of the viewport
4+
must not cause a horizontal scrollbar which would otherwise not have been there.
5+
</p>
6+
<pf-button disabled>Spacer</pf-button>
7+
<pf-button disabled>Spacer</pf-button>
8+
<pf-button disabled>Spacer</pf-button>
9+
<pf-button disabled>Spacer</pf-button>
10+
<pf-button disabled>Spacer</pf-button>
11+
<pf-button disabled>Spacer</pf-button>
12+
<pf-button disabled>Spacer</pf-button>
13+
<pf-button disabled>Spacer</pf-button>
14+
<pf-button disabled>Spacer</pf-button>
15+
<pf-button disabled>Spacer</pf-button>
16+
<pf-button disabled>Spacer</pf-button>
17+
<pf-button disabled>Spacer</pf-button>
18+
<pf-popover heading="Popover heading" footer="Popover footer">
19+
<p slot="body">In this popover, the content is quite wide,
20+
so as to force a horizontal scrollbar if the
21+
dialog content is improperly rendered.</p>
22+
<pf-button>Toggle popover</pf-button>
23+
</pf-popover>
24+
25+
26+
<script type="module">
27+
import '@patternfly/elements/pf-popover/pf-popover.js';
28+
import '@patternfly/elements/pf-button/pf-button.js';
29+
</script>

elements/pf-popover/pf-popover.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@ export class PfPopover extends LitElement {
312312
@query('#trigger') private _slottedTrigger?: HTMLElement | null;
313313
@query('#arrow') private _arrow!: HTMLDivElement;
314314

315+
/** True before the show animation begins and after the hide animation ends */
316+
#hideDialog = true;
317+
315318
#referenceTrigger?: HTMLElement | null = null;
316319

317320
#float = new FloatingDOMController(this, {
@@ -357,6 +360,7 @@ export class PfPopover extends LitElement {
357360
@keydown="${this.#onKeydown}"
358361
@click="${this.toggle}"></slot>
359362
<dialog id="popover"
363+
?hidden="${this.#hideDialog}"
360364
aria-labelledby="heading"
361365
aria-describedby="body"
362366
aria-label=${ifDefined(this.label)}>
@@ -462,6 +466,8 @@ export class PfPopover extends LitElement {
462466
* Opens the popover
463467
*/
464468
@bound async show() {
469+
this.#hideDialog = false;
470+
this.requestUpdate();
465471
this.dispatchEvent(new PopoverShowEvent());
466472
await this.updateComplete;
467473
await this.#float.show({
@@ -484,6 +490,8 @@ export class PfPopover extends LitElement {
484490
this._popover?.close();
485491
this.dispatchEvent(new PopoverHiddenEvent());
486492
PfPopover.instances.delete(this);
493+
this.#hideDialog = true;
494+
this.requestUpdate();
487495
}
488496
}
489497

0 commit comments

Comments
 (0)