Skip to content

Commit 27cd6f9

Browse files
committed
feat(Drawer): Add support for tooltips on menu items
1 parent 1c5faa3 commit 27cd6f9

File tree

2 files changed

+44
-30
lines changed

2 files changed

+44
-30
lines changed

components/mdc/Drawer/Drawer.svelte

+33-27
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { MDCDrawer } from '@material/drawer'
55
import { MDCList } from '@material/list'
66
import Button from '../Button'
77
import IconButton from '../IconButton/IconButton.svelte'
8+
import Tooltip from '../Tooltip/Tooltip.svelte'
89
import { beforeUrlChange, goto } from '@roxi/routify'
910
import { onMount } from 'svelte'
1011
import TopAppBar from '../TopAppBar'
@@ -125,36 +126,41 @@ main {
125126
<!-- override built-in padding so height 100 works correctly without creating a vertical scroller -->
126127
<!-- changing the list to flex causes the margins to not collapse -->
127128
<nav class="mdc-list flex column p-0" class:h-100={isFullHeightMenu} on:click={onListClick} bind:this={listElement}>
128-
{#each menuItems as { icon, label, url, hide, button }, i}
129+
{#each menuItems as { icon, label, url, hide, button, tooltip }, i}
129130
{#if label === '--break--'}
130131
<span class="grow-1" />
131132
{:else if !hide}
132-
{#if button && isNotMini}
133-
<Button class="m-1" raised prependIcon={icon} {url}>{label}</Button>
134-
{:else if button}
135-
<IconButton class="mdc-theme--primary pl-1" {icon} ariaLabel={label} on:click={() => $goto(url)} />
136-
{:else if url}
137-
<a
138-
class="mdc-list-item"
139-
class:mdc-list-item--activated={isMenuItemActive(currentUrl, url)}
140-
href={url}
141-
aria-current={isMenuItemActive(currentUrl, url) ? 'page' : null}
142-
tabindex={i === 0 ? 0 : undefined}
143-
>
144-
<span class="mdc-list-item__ripple" />
145-
{#if icon}
146-
<i class="material-icons mdc-list-item__graphic" aria-hidden="true">{icon}</i>
147-
{/if}
148-
149-
{#if label && isNotMini}
150-
<span class="mdc-list-item__text">{label}</span>
151-
{/if}
152-
</a>
153-
{:else}
154-
<hr
155-
class="mdc-list-divider mdc-list-divider--inset-leading mdc-list-divider--inset-trailing"
156-
role="separator"
157-
/>
133+
<Tooltip.Wrapper ariaDescribedBy={label + '-tooltip'}>
134+
{#if button && isNotMini}
135+
<Button class="m-1" raised prependIcon={icon} {url}>{label}</Button>
136+
{:else if button}
137+
<IconButton class="mdc-theme--primary pl-1" {icon} ariaLabel={label} on:click={() => $goto(url)} />
138+
{:else if url}
139+
<a
140+
class="mdc-list-item"
141+
class:mdc-list-item--activated={isMenuItemActive(currentUrl, url)}
142+
href={url}
143+
aria-current={isMenuItemActive(currentUrl, url) ? 'page' : null}
144+
tabindex={i === 0 ? 0 : undefined}
145+
>
146+
<span class="mdc-list-item__ripple" />
147+
{#if icon}
148+
<i class="material-icons mdc-list-item__graphic" aria-hidden="true">{icon}</i>
149+
{/if}
150+
151+
{#if label && isNotMini}
152+
<span class="mdc-list-item__text">{label}</span>
153+
{/if}
154+
</a>
155+
{:else}
156+
<hr
157+
class="mdc-list-divider mdc-list-divider--inset-leading mdc-list-divider--inset-trailing"
158+
role="separator"
159+
/>
160+
{/if}
161+
</Tooltip.Wrapper>
162+
{#if tooltip}
163+
<Tooltip tooltipID={label + '-tooltip'}>{tooltip}</Tooltip>
158164
{/if}
159165
{/if}
160166
{/each}

stories/Drawer.stories.svelte

+11-3
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,25 @@ const args = {
1212
{
1313
url: './',
1414
icon: 'account_circle',
15-
label: 'reload',
15+
label: 'account',
16+
tooltip: 'user account',
1617
},
1718
{
1819
url: './',
1920
icon: 'face',
20-
label: 'reload',
21+
label: 'bio',
2122
},
2223
{
2324
url: './',
2425
icon: 'add',
25-
label: 'reload',
26+
label: 'add stuff',
27+
tooltip: 'add things',
28+
},
29+
{
30+
url: './',
31+
icon: 'remove',
32+
label: 'remove stuff',
33+
tooltip: 'remove things',
2634
},
2735
{
2836
url: './',

0 commit comments

Comments
 (0)