fix: template panel tooltip overflow (#11304)
Close #10171 Fixes [BS-2577](https://linear.app/affine-design/issue/BS-2577/title-overflow-in-edgeless-mode-in-web-interface)
This commit is contained in:
@@ -471,6 +471,7 @@ export class EdgelessTemplatePanel extends WithDisposable(LitElement) {
|
|||||||
${template.name
|
${template.name
|
||||||
? html`<affine-tooltip
|
? html`<affine-tooltip
|
||||||
.offset=${12}
|
.offset=${12}
|
||||||
|
.autoHide=${true}
|
||||||
tip-position="top"
|
tip-position="top"
|
||||||
>
|
>
|
||||||
${template.name}
|
${template.name}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import {
|
|||||||
arrow,
|
arrow,
|
||||||
type ComputePositionReturn,
|
type ComputePositionReturn,
|
||||||
flip,
|
flip,
|
||||||
|
hide,
|
||||||
offset,
|
offset,
|
||||||
type Placement,
|
type Placement,
|
||||||
shift,
|
shift,
|
||||||
@@ -142,6 +143,7 @@ export class Tooltip extends LitElement {
|
|||||||
// return null;
|
// return null;
|
||||||
if (this.hidden) return null;
|
if (this.hidden) return null;
|
||||||
let arrowStyles: StyleInfo = {};
|
let arrowStyles: StyleInfo = {};
|
||||||
|
let tooltipStyles: StyleInfo = {};
|
||||||
return {
|
return {
|
||||||
template: ({ positionSlot, updatePortal }) => {
|
template: ({ positionSlot, updatePortal }) => {
|
||||||
positionSlot.subscribe(data => {
|
positionSlot.subscribe(data => {
|
||||||
@@ -152,6 +154,15 @@ export class Tooltip extends LitElement {
|
|||||||
} else {
|
} else {
|
||||||
arrowStyles = {};
|
arrowStyles = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.autoHide) {
|
||||||
|
tooltipStyles.visibility = data.middlewareData.hide
|
||||||
|
?.referenceHidden
|
||||||
|
? 'hidden'
|
||||||
|
: '';
|
||||||
|
arrowStyles.visibility = tooltipStyles.visibility;
|
||||||
|
}
|
||||||
|
|
||||||
updatePortal();
|
updatePortal();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -163,7 +174,13 @@ export class Tooltip extends LitElement {
|
|||||||
<style>
|
<style>
|
||||||
${this._getStyles()}
|
${this._getStyles()}
|
||||||
</style>
|
</style>
|
||||||
<div class="affine-tooltip" role="tooltip">${children}</div>
|
<div
|
||||||
|
class="affine-tooltip"
|
||||||
|
role="tooltip"
|
||||||
|
style=${styleMap(tooltipStyles)}
|
||||||
|
>
|
||||||
|
${children}
|
||||||
|
</div>
|
||||||
<div class="arrow" style=${styleMap(arrowStyles)}></div>
|
<div class="arrow" style=${styleMap(arrowStyles)}></div>
|
||||||
`;
|
`;
|
||||||
},
|
},
|
||||||
@@ -177,6 +194,7 @@ export class Tooltip extends LitElement {
|
|||||||
arrow({
|
arrow({
|
||||||
element: portalRoot.shadowRoot!.querySelector('.arrow')!,
|
element: portalRoot.shadowRoot!.querySelector('.arrow')!,
|
||||||
}),
|
}),
|
||||||
|
this.autoHide && hide({ strategy: 'referenceHidden' }),
|
||||||
],
|
],
|
||||||
autoUpdate: true,
|
autoUpdate: true,
|
||||||
}),
|
}),
|
||||||
@@ -257,6 +275,14 @@ export class Tooltip extends LitElement {
|
|||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
accessor autoFlip = true;
|
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.
|
* shifts the floating element to keep it in view.
|
||||||
* this prevents the floating element from
|
* this prevents the floating element from
|
||||||
|
|||||||
Reference in New Issue
Block a user