diff --git a/docs/components/tooltip.md b/docs/components/tooltip.md index cd6d92aa7..db5307b12 100644 --- a/docs/components/tooltip.md +++ b/docs/components/tooltip.md @@ -343,6 +343,26 @@ const App = () => ( ); ``` +### Setting a Maximum Width + +Use the `--max-width` custom property to change the width the tooltip can grow to before wrapping occurs. + +```html preview + + Hover me + +``` + +```jsx react +import { SlButton, SlTooltip } from '@shoelace-style/shoelace/dist/react'; + +const App = () => ( + + Hover Me + +); +``` + ### Hoisting Tooltips will be clipped if they're inside a container that has `overflow: auto|hidden|scroll`. The `hoist` attribute forces the tooltip to use a fixed positioning strategy, allowing it to break out of the container. In this case, the tooltip will be positioned relative to its containing block, which is usually the viewport unless an ancestor uses a `transform`, `perspective`, or `filter`. [Refer to this page](https://developer.mozilla.org/en-US/docs/Web/CSS/position#fixed) for more details. diff --git a/src/components/tooltip/tooltip.styles.ts b/src/components/tooltip/tooltip.styles.ts index 4ffeb1301..7bae9a385 100644 --- a/src/components/tooltip/tooltip.styles.ts +++ b/src/components/tooltip/tooltip.styles.ts @@ -39,6 +39,7 @@ export default css` } .tooltip__body { + width: max-content; max-width: var(--max-width); border-radius: var(--sl-tooltip-border-radius); background-color: var(--sl-tooltip-background-color); diff --git a/src/components/tooltip/tooltip.ts b/src/components/tooltip/tooltip.ts index 093a2cea9..a20a51df6 100644 --- a/src/components/tooltip/tooltip.ts +++ b/src/components/tooltip/tooltip.ts @@ -31,7 +31,7 @@ import type { CSSResultGroup } from 'lit'; * @csspart base__arrow - The popup's `arrow` part. Use this to target the tooltip's arrow. * @csspart body - The tooltip's body. * - * @cssproperty --max-width - The maximum width of the tooltip. + * @cssproperty --max-width - The maximum width of the tooltip before its content will wrap. * @cssproperty --hide-delay - The amount of time to wait before hiding the tooltip when hovering. * @cssproperty --show-delay - The amount of time to wait before showing the tooltip when hovering. *