From 51dddc10be8f3b23ffc2a03ec915341f8f54d70b Mon Sep 17 00:00:00 2001 From: doouding Date: Mon, 31 Mar 2025 09:51:33 +0000 Subject: [PATCH] fix: template panel tooltip overflow (#11304) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Close #10171 Fixes [BS-2577](https://linear.app/affine-design/issue/BS-2577/​title-overflow-in-edgeless-mode-in-web-interface) --- .../toolbar/template/template-panel.ts | 1 + .../affine/components/src/toolbar/tooltip.ts | 28 ++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/blocksuite/affine/blocks/block-root/src/edgeless/components/toolbar/template/template-panel.ts b/blocksuite/affine/blocks/block-root/src/edgeless/components/toolbar/template/template-panel.ts index 8a1db741c..b5b5ee7c6 100644 --- a/blocksuite/affine/blocks/block-root/src/edgeless/components/toolbar/template/template-panel.ts +++ b/blocksuite/affine/blocks/block-root/src/edgeless/components/toolbar/template/template-panel.ts @@ -471,6 +471,7 @@ export class EdgelessTemplatePanel extends WithDisposable(LitElement) { ${template.name ? html` ${template.name} diff --git a/blocksuite/affine/components/src/toolbar/tooltip.ts b/blocksuite/affine/components/src/toolbar/tooltip.ts index 1d080f0fb..a516ea62b 100644 --- a/blocksuite/affine/components/src/toolbar/tooltip.ts +++ b/blocksuite/affine/components/src/toolbar/tooltip.ts @@ -3,6 +3,7 @@ import { arrow, type ComputePositionReturn, flip, + hide, offset, type Placement, shift, @@ -142,6 +143,7 @@ export class Tooltip extends LitElement { // return null; if (this.hidden) return null; let arrowStyles: StyleInfo = {}; + let tooltipStyles: StyleInfo = {}; return { template: ({ positionSlot, updatePortal }) => { positionSlot.subscribe(data => { @@ -152,6 +154,15 @@ export class Tooltip extends LitElement { } else { arrowStyles = {}; } + + if (this.autoHide) { + tooltipStyles.visibility = data.middlewareData.hide + ?.referenceHidden + ? 'hidden' + : ''; + arrowStyles.visibility = tooltipStyles.visibility; + } + updatePortal(); }); @@ -163,7 +174,13 @@ export class Tooltip extends LitElement { - +
`; }, @@ -177,6 +194,7 @@ export class Tooltip extends LitElement { arrow({ element: portalRoot.shadowRoot!.querySelector('.arrow')!, }), + this.autoHide && hide({ strategy: 'referenceHidden' }), ], autoUpdate: true, }), @@ -257,6 +275,14 @@ export class Tooltip extends LitElement { @property({ attribute: false }) accessor autoFlip = true; + /** + * Hide the tooltip when the reference element is not in view. + * + * See https://floating-ui.com/docs/hide + */ + @property({ attribute: false }) + accessor autoHide = false; + /** * shifts the floating element to keep it in view. * this prevents the floating element from