diff --git a/change/@fluentui-web-components-f87a2b96-d977-4138-8cb9-8cad4b13d8a8.json b/change/@fluentui-web-components-f87a2b96-d977-4138-8cb9-8cad4b13d8a8.json new file mode 100644 index 0000000000000..f9cd17c85f0c5 --- /dev/null +++ b/change/@fluentui-web-components-f87a2b96-d977-4138-8cb9-8cad4b13d8a8.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "fix tooltip positioning styles for 'below-end' option", + "packageName": "@fluentui/web-components", + "email": "863023+radium-v@users.noreply.github.com", + "dependentChangeType": "patch" +} diff --git a/packages/web-components/src/tooltip/tooltip.stories.ts b/packages/web-components/src/tooltip/tooltip.stories.ts index 29040e851e0bd..9a1de32d562e7 100644 --- a/packages/web-components/src/tooltip/tooltip.stories.ts +++ b/packages/web-components/src/tooltip/tooltip.stories.ts @@ -1,27 +1,31 @@ -import { html, render, repeat } from '@microsoft/fast-element'; +import { css, html, repeat } from '@microsoft/fast-element'; import { uniqueId } from '@microsoft/fast-web-utilities'; -import { Meta, renderComponent, Story } from '../helpers.stories.js'; +import { type Meta, renderComponent, type StoryArgs, type StoryObj } from '../helpers.stories.js'; import { definition } from './tooltip.definition.js'; -import { Tooltip } from './tooltip.js'; +import type { Tooltip as FluentTooltip } from './tooltip.js'; import { TooltipPositioningOption } from './tooltip.options.js'; -const storyTemplate = () => { - const id = uniqueId('anchor-'); +type Story = StoryObj; - return html` -
- Hover me - - ${story => story.slottedContent?.()} - -
- `; -}; +const tooltipTemplate = html>` + + ${story => story.slottedContent?.()} + +`; + +const storyTemplate = html>` + Hover me + ${tooltipTemplate} +`; export default { title: 'Components/Tooltip', component: definition.name, - render: renderComponent(storyTemplate()), + render: renderComponent(storyTemplate), argTypes: { anchor: { description: 'The target element for the tooltip to anchor on', @@ -48,105 +52,172 @@ export default { }, }, }, -} as unknown as Meta; - -export const Default: Story = args => { - return renderComponent(html`${render(args, storyTemplate)}`)(args); -}; -Default.args = { - slottedContent: () => html`Really long tooltip content goes here. lorem ipsum dolor sit amet.`, -}; +} as Meta; -const iconArrowRight = (rotation = 0) => html` - -`; - -const iconArrowLeft = (rotation = 0) => html` - -`; +export const Default: Story = { + args: { + slottedContent: () => 'Really long tooltip content goes here. Lorem ipsum dolor sit amet.', + }, + decorators: [ + (Story, { canvasElement }) => { + const story = Story() as DocumentFragment; + const id = uniqueId('anchor-'); + const link = story.querySelector('fluent-link'); + link?.setAttribute('id', link.id || id); -const iconArrowUp = (rotation = 0) => html` - -`; + const tooltip = story.querySelector('fluent-tooltip'); + tooltip?.setAttribute('anchor', tooltip.anchor || id); -const glyphs = { - 'above-start': iconArrowRight(-90), - above: iconArrowUp(), - 'above-end': iconArrowLeft(90), - 'below-start': iconArrowLeft(-90), - below: iconArrowUp(180), - 'below-end': iconArrowRight(90), - 'before-top': iconArrowLeft(0), - before: iconArrowUp(-90), - 'before-bottom': iconArrowRight(180), - 'after-top': iconArrowRight(), - after: iconArrowUp(90), - 'after-bottom': iconArrowLeft(180), + canvasElement.style.textAlign = 'center'; + return story; + }, + ], }; -const positionButtonTemplate = html` - - ${x => glyphs[x.id as keyof typeof glyphs]} - -`; +export const Positioning: Story = { + render: renderComponent(html>` + ${repeat( + [ + { + href: '#arrow-step-back-20-regular', + id: 'above-start', + positioning: 'above-start', + transform: 'rotate(-90deg) scaleX(-1)', + slottedContent: () => 'above-start', + }, + { + href: '#arrow-step-out-20-regular', + id: 'above', + positioning: 'above', + transform: 'rotate(0deg)', + slottedContent: () => 'above', + }, + { + href: '#arrow-step-back-20-regular', + id: 'above-end', + positioning: 'above-end', + transform: 'rotate(90deg)', + slottedContent: () => 'above-end', + }, + { + href: '#arrow-step-back-20-regular', + id: 'before-top', + positioning: 'before-top', + transform: 'rotate(0deg)', + slottedContent: () => 'before-top', + }, + { + href: '#arrow-step-out-20-regular', + id: 'before', + positioning: 'before', + transform: 'rotate(-90deg)', + slottedContent: () => 'before', + }, + { + href: '#arrow-step-back-20-regular', + id: 'before-bottom', + positioning: 'before-bottom', + transform: 'rotate(180deg) scaleX(-1)', + slottedContent: () => 'before-bottom', + }, + { + href: '#arrow-step-back-20-regular', + id: 'after-top', + positioning: 'after-top', + transform: 'rotate(0deg) scaleX(-1)', + slottedContent: () => 'after-top', + }, + { + href: '#arrow-step-out-20-regular', + id: 'after', + positioning: 'after', + transform: 'rotate(90deg)', + slottedContent: () => 'after', + }, + { + href: '#arrow-step-back-20-regular', + id: 'after-bottom', + positioning: 'after-bottom', + transform: 'rotate(180deg)', + slottedContent: () => 'after-bottom', + }, + { + href: '#arrow-step-back-20-regular', + id: 'below-start', + positioning: 'below-start', + transform: 'rotate(-90deg)', + slottedContent: () => 'below-start', + }, + { + href: '#arrow-step-out-20-regular', + id: 'below', + positioning: 'below', + transform: 'rotate(180deg)', + slottedContent: () => 'below', + }, + { + href: '#arrow-step-back-20-regular', + id: 'below-end', + positioning: 'below-end', + transform: 'rotate(90deg) scaleX(-1)', + slottedContent: () => 'below-end', + }, + ], -const positionTooltipTemplate = html` - ${x => x.id} -`; + html` + + + + ${tooltipTemplate} + `, + )} + `), + decorators: [ + (Story, context) => { + const { args, canvasElement } = context; + const story = Story() as DocumentFragment; -export const Positioning: Story = renderComponent(html` -
- -
${repeat(x => x.storyItems, positionButtonTemplate)}
+ const styles = css` + .grid { + display: grid; + margin: auto; + gap: 4px; + width: min-content; + grid-template-areas: + '. above-start above above-end .' + 'before-top . . . after-top' + 'before . . . after' + 'before-bottom . . . after-bottom' + '. below-start below below-end .'; + } + `; + styles.addStylesTo(canvasElement); + canvasElement.classList.add('grid'); - ${repeat(x => x.storyItems, positionTooltipTemplate)} -
-`).bind({}); + // Rendering the sprite sheet here prevents it from being included in the code snippet + html` + + + + + + + + + `.render(args, story); -Positioning.args = { - storyItems: Object.keys(TooltipPositioningOption).map(id => ({ id })), + return story; + }, + ], }; diff --git a/packages/web-components/src/tooltip/tooltip.styles.ts b/packages/web-components/src/tooltip/tooltip.styles.ts index 3b9327aaabd37..70fc8548ecab6 100644 --- a/packages/web-components/src/tooltip/tooltip.styles.ts +++ b/packages/web-components/src/tooltip/tooltip.styles.ts @@ -45,6 +45,7 @@ export const styles = css` line-height: ${lineHeightBase200}; margin: unset; /* Remove browser default for [popover] */ max-width: 240px; + overflow: visible; padding: 4px ${spacingHorizontalMNudge} 6px; position: absolute; position-area: var(--position-area); @@ -85,7 +86,7 @@ export const styles = css` --position-area: ${TooltipPositioningOption.below}; } :host([positioning='below-end']) { - --position-area: ${TooltipPositioningOption.below}; + --position-area: ${TooltipPositioningOption['below-end']}; } :host([positioning='before-top']) { --position-area: ${TooltipPositioningOption['before-top']};