-
Notifications
You must be signed in to change notification settings - Fork 218
docs: document tooltip support on menu items #5568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2ce8930
docs: document tooltip support on menu items
vursen 14527a3
Apply suggestion from @vursen
vursen a5bce93
Merge branch 'main' into docs/menu-item-tooltips
vursen 6d8f1d4
Merge branch 'main' into docs/menu-item-tooltips
vursen 2631c33
docs: simplify menu tooltip sections
vursen 0f89b09
Merge branch 'main' into docs/menu-item-tooltips
vursen ddaa687
Update articles/components/menu-bar/index.adoc
vursen 693bf7a
Update articles/components/context-menu/index.adoc
vursen 268d6ba
Update frontend/demo/component/contextmenu/react/context-menu-tooltip…
vursen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
frontend/demo/component/contextmenu/context-menu-tooltip.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import 'Frontend/demo/init'; // hidden-source-line | ||
| import '@vaadin/context-menu'; | ||
| import '@vaadin/grid'; | ||
| import '@vaadin/tooltip'; | ||
| import { html, LitElement } from 'lit'; | ||
| import { customElement, state } from 'lit/decorators.js'; | ||
| import type { Grid } from '@vaadin/grid'; | ||
| import { getPeople } from 'Frontend/demo/domain/DataService'; | ||
| import { applyTheme } from 'Frontend/demo/theme'; | ||
| import type Person from 'Frontend/generated/com/vaadin/demo/domain/Person'; | ||
|
|
||
| @customElement('context-menu-tooltip') | ||
| export class Example extends LitElement { | ||
| protected override createRenderRoot() { | ||
| const root = super.createRenderRoot(); | ||
| applyTheme(root); | ||
| return root; | ||
| } | ||
|
|
||
| // tag::snippet[] | ||
| @state() | ||
| private items = [ | ||
| { text: 'Edit', tooltip: 'Edit selected person' }, | ||
| { | ||
| text: 'Share', | ||
| children: [ | ||
| { text: 'Copy link', tooltip: 'Copy a shareable link to the clipboard' }, | ||
| { | ||
| text: 'Email', | ||
| tooltip: 'Send the contact details by email', | ||
| tooltipPosition: 'end', | ||
| }, | ||
| ], | ||
| }, | ||
| ]; | ||
| // end::snippet[] | ||
|
|
||
| @state() | ||
| private gridItems: Person[] = []; | ||
|
|
||
| protected override async firstUpdated() { | ||
| this.gridItems = (await getPeople({ count: 5 })).people; | ||
| } | ||
|
|
||
| protected override render() { | ||
| return html` | ||
| <!-- tag::snippethtml[] --> | ||
| <vaadin-context-menu .items=${this.items}> | ||
| <vaadin-tooltip slot="tooltip"></vaadin-tooltip> | ||
| <vaadin-grid | ||
| all-rows-visible | ||
| .items=${this.gridItems} | ||
| @vaadin-contextmenu=${this.onContextMenu} | ||
| > | ||
| <vaadin-grid-column path="firstName"></vaadin-grid-column> | ||
| <vaadin-grid-column path="lastName"></vaadin-grid-column> | ||
| <vaadin-grid-column path="email"></vaadin-grid-column> | ||
| </vaadin-grid> | ||
| </vaadin-context-menu> | ||
| <!-- end::snippethtml[] --> | ||
| `; | ||
| } | ||
|
|
||
| onContextMenu(e: MouseEvent) { | ||
| // Prevent opening context menu on header row. | ||
| const target = e.currentTarget as Grid<Person>; | ||
| if (target.getEventContext(e).section !== 'body') { | ||
| e.stopPropagation(); | ||
| } | ||
| } | ||
| } |
64 changes: 64 additions & 0 deletions
64
frontend/demo/component/contextmenu/react/context-menu-tooltip.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import { reactExample } from 'Frontend/demo/react-example'; // hidden-source-line | ||
| import React, { useEffect, useRef } from 'react'; | ||
| import { useSignals } from '@preact/signals-react/runtime'; // hidden-source-line | ||
| import { useSignal } from '@vaadin/hilla-react-signals'; | ||
| import { ContextMenu, Tooltip } from '@vaadin/react-components'; | ||
| import { Grid, type GridElement } from '@vaadin/react-components/Grid.js'; | ||
| import { GridColumn } from '@vaadin/react-components/GridColumn.js'; | ||
| import { getPeople } from 'Frontend/demo/domain/DataService'; | ||
| import type Person from 'Frontend/generated/com/vaadin/demo/domain/Person'; | ||
|
|
||
| function Example() { | ||
| useSignals(); // hidden-source-line | ||
| const gridItems = useSignal<Person[]>([]); | ||
| const gridRef = useRef<GridElement>(null); | ||
|
|
||
| useEffect(() => { | ||
| getPeople({ count: 5 }).then(({ people }) => { | ||
| gridItems.value = people; | ||
| }); | ||
| }, []); | ||
|
|
||
| useEffect(() => { | ||
| const grid = gridRef.current; | ||
| if (grid) { | ||
| // Workaround: Prevent opening context menu on header row. | ||
| // @ts-expect-error vaadin-contextmenu isn't a GridElement event. | ||
| grid.addEventListener('vaadin-contextmenu', (e) => { | ||
| if (grid.getEventContext(e).section !== 'body') { | ||
| e.stopPropagation(); | ||
| } | ||
| }); | ||
| } | ||
| }, [gridRef.current]); | ||
|
|
||
| // tag::snippet[] | ||
| const items = [ | ||
| { text: 'Edit', tooltip: 'Edit selected person' }, | ||
| { | ||
| text: 'Share', | ||
| children: [ | ||
| { text: 'Copy link', tooltip: 'Copy a shareable link to the clipboard' }, | ||
| { | ||
| text: 'Email', | ||
| tooltip: 'Send the contact details by email', | ||
| tooltipPosition: 'end', | ||
| }, | ||
| ], | ||
| }, | ||
| ]; | ||
|
|
||
| return ( | ||
| <ContextMenu items={items}> | ||
| <Tooltip slot="tooltip" /> | ||
| <Grid allRowsVisible items={gridItems.value} ref={gridRef}> | ||
| <GridColumn path="firstName" /> | ||
| <GridColumn path="lastName" /> | ||
| <GridColumn path="email" /> | ||
| </Grid> | ||
| </ContextMenu> | ||
| ); | ||
| // end::snippet[] | ||
| } | ||
|
|
||
| export default reactExample(Example); // hidden-source-line |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/java/com/vaadin/demo/component/contextmenu/ContextMenuTooltip.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package com.vaadin.demo.component.contextmenu; | ||
|
|
||
| import com.vaadin.demo.DemoExporter; // hidden-source-line | ||
| import com.vaadin.demo.domain.DataService; | ||
| import com.vaadin.demo.domain.Person; | ||
| import com.vaadin.flow.component.grid.Grid; | ||
| import com.vaadin.flow.component.grid.contextmenu.GridContextMenu; | ||
| import com.vaadin.flow.component.grid.contextmenu.GridMenuItem; | ||
| import com.vaadin.flow.component.grid.contextmenu.GridSubMenu; | ||
| import com.vaadin.flow.component.html.Div; | ||
| import com.vaadin.flow.component.shared.Tooltip.TooltipPosition; | ||
| import com.vaadin.flow.router.Route; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Route("context-menu-tooltip") | ||
| public class ContextMenuTooltip extends Div { | ||
|
|
||
| private List<Person> people = DataService.getPeople(5); | ||
|
|
||
| public ContextMenuTooltip() { | ||
| Grid<Person> grid = new Grid(); | ||
| grid.setAllRowsVisible(true); | ||
| grid.setItems(people); | ||
|
|
||
| grid.addColumn(Person::getFirstName).setHeader("First name"); | ||
| grid.addColumn(Person::getLastName).setHeader("Last name"); | ||
| grid.addColumn(Person::getEmail).setHeader("Email"); | ||
|
|
||
| // tag::snippet[] | ||
| GridContextMenu<Person> menu = grid.addContextMenu(); | ||
| GridMenuItem<Person> edit = menu.addItem("Edit"); | ||
| edit.setTooltipText("Edit selected person"); | ||
|
|
||
| GridMenuItem<Person> share = menu.addItem("Share"); | ||
| GridSubMenu<Person> shareSubMenu = share.getSubMenu(); | ||
| shareSubMenu.addItem("Copy link") | ||
| .setTooltipText("Copy a shareable link to the clipboard"); | ||
| GridMenuItem<Person> email = shareSubMenu.addItem("Email"); | ||
| email.setTooltipText("Send the contact details by email"); | ||
| email.setTooltipPosition(TooltipPosition.END); | ||
| // end::snippet[] | ||
|
|
||
| add(grid); | ||
| } | ||
|
|
||
| public static class Exporter extends DemoExporter<ContextMenuTooltip> { // hidden-source-line | ||
| } // hidden-source-line | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.