impr: improve select menu semantics
This commit is contained in:
12 files changed
+57
-74
No files matched your search
@@ -88,14 +88,12 @@
|
|||||||
</Option>
|
</Option>
|
||||||
</Select>
|
</Select>
|
||||||
{#if selected?.startsWith('Top')}
|
{#if selected?.startsWith('Top')}
|
||||||
<div transition:fly={{ easing: backOut, x: 2 }}>
|
|
||||||
<Select
|
<Select
|
||||||
class="border-l-0 rounded-l-none"
|
class="border-l-0 rounded-l-none"
|
||||||
bind:value={selected}
|
bind:value={selected}
|
||||||
onchange={() => {
|
onchange={() => {
|
||||||
sort = 'TopAll'
|
sort = 'TopAll'
|
||||||
if (navigate)
|
if (navigate) searchParam(page.url, 'sort', selected, 'page', 'cursor')
|
||||||
searchParam(page.url, 'sort', selected, 'page', 'cursor')
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{#snippet customLabel()}
|
{#snippet customLabel()}
|
||||||
@@ -135,6 +133,5 @@
|
|||||||
{$t('filter.sort.top.time.hour')}
|
{$t('filter.sort.top.time.hour')}
|
||||||
</Option>
|
</Option>
|
||||||
</Select>
|
</Select>
|
||||||
</div>
|
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
@@ -144,8 +144,9 @@
|
|||||||
>
|
>
|
||||||
{#if showCommunity && community}
|
{#if showCommunity && community}
|
||||||
<Popover>
|
<Popover>
|
||||||
{#snippet target()}
|
{#snippet target(attachment)}
|
||||||
<button
|
<button
|
||||||
|
{@attach attachment}
|
||||||
class={[
|
class={[
|
||||||
'row-span-2 shrink-0 mr-2 self-center group/btn',
|
'row-span-2 shrink-0 mr-2 self-center group/btn',
|
||||||
'bg-slate-200 dark:bg-zinc-800 rounded-lg cursor-pointer',
|
'bg-slate-200 dark:bg-zinc-800 rounded-lg cursor-pointer',
|
||||||
@@ -177,6 +178,7 @@
|
|||||||
rounding="2xl"
|
rounding="2xl"
|
||||||
elevation="high"
|
elevation="high"
|
||||||
class="max-w-2xl w-full max-h-128 overflow-auto"
|
class="max-w-2xl w-full max-h-128 overflow-auto"
|
||||||
|
data-autoclose="false"
|
||||||
>
|
>
|
||||||
{#await import('../community/CommunityHeader.svelte') then { default: CommunityHeader }}
|
{#await import('../community/CommunityHeader.svelte') then { default: CommunityHeader }}
|
||||||
<CommunityHeader {community} {subscribed} />
|
<CommunityHeader {community} {subscribed} />
|
||||||
|
|||||||
@@ -41,7 +41,7 @@
|
|||||||
'transition-transform duration-300 ease-out',
|
'transition-transform duration-300 ease-out',
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
<Icon src={open ? Minus : Plus} size="16" micro class={[]} />
|
<Icon src={open ? Minus : Plus} size="15" micro class={[]} />
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
<div
|
<div
|
||||||
|
|||||||
@@ -10,23 +10,21 @@
|
|||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { page } from '$app/state'
|
import { page } from '$app/state'
|
||||||
|
import { t } from '$lib/i18n/translations'
|
||||||
import { Button, Material, toast } from 'mono-svelte'
|
import { Button, Material, toast } from 'mono-svelte'
|
||||||
|
import { focusTrap } from 'svelte-focus-trap'
|
||||||
import { Icon, Share, XMark } from 'svelte-hero-icons'
|
import { Icon, Share, XMark } from 'svelte-hero-icons'
|
||||||
import { expoOut } from 'svelte/easing'
|
import { expoOut } from 'svelte/easing'
|
||||||
import { fade, scale } from 'svelte/transition'
|
import { fade, scale } from 'svelte/transition'
|
||||||
import { focusTrap } from 'svelte-focus-trap'
|
|
||||||
import { t } from '$lib/i18n/translations'
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
/**
|
/**
|
||||||
* The full-resolution image URL
|
* The full-resolution image URL
|
||||||
*/
|
*/
|
||||||
alt?: string
|
alt?: string
|
||||||
class?: string
|
|
||||||
children?: import('svelte').Snippet
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let { alt = '', class: clazz = '', children }: Props = $props()
|
let { alt = '' }: Props = $props()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if page.state.openImage || '' != ''}
|
{#if page.state.openImage || '' != ''}
|
||||||
@@ -88,7 +86,3 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<button onclick={() => history.back()} class="contents {clazz}">
|
|
||||||
{@render children?.()}
|
|
||||||
</button>
|
|
||||||
@@ -133,10 +133,7 @@
|
|||||||
{/snippet}
|
{/snippet}
|
||||||
{$t('nav.menu.settings')}
|
{$t('nav.menu.settings')}
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
<!--svelte-ignore a11y_click_events_have_key_events-->
|
<Select bind:value={theme.colorScheme} size="sm" placement="left">
|
||||||
<!--svelte-ignore a11y_no_static_element_interactions-->
|
|
||||||
<div onclick={e => e.stopPropagation()}>
|
|
||||||
<Select bind:value={theme.colorScheme} size="sm">
|
|
||||||
{#snippet target(attachment)}
|
{#snippet target(attachment)}
|
||||||
<MenuButton
|
<MenuButton
|
||||||
{@attach attachment}
|
{@attach attachment}
|
||||||
@@ -146,6 +143,7 @@
|
|||||||
? Sun
|
? Sun
|
||||||
: Moon}
|
: Moon}
|
||||||
class=" w-full"
|
class=" w-full"
|
||||||
|
nest
|
||||||
>
|
>
|
||||||
{$t('nav.menu.colorscheme.label')}
|
{$t('nav.menu.colorscheme.label')}
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
@@ -159,8 +157,7 @@
|
|||||||
{$t('nav.menu.colorscheme.dark')}
|
{$t('nav.menu.colorscheme.dark')}
|
||||||
</Option>
|
</Option>
|
||||||
{/snippet}
|
{/snippet}
|
||||||
</Select>
|
</Select>
|
||||||
</div>
|
|
||||||
<MenuButton href="/theme">
|
<MenuButton href="/theme">
|
||||||
{#snippet prefix()}
|
{#snippet prefix()}
|
||||||
<Icon src={Swatch} size="16" micro />
|
<Icon src={Swatch} size="16" micro />
|
||||||
|
|||||||
@@ -11,8 +11,10 @@
|
|||||||
import {
|
import {
|
||||||
ArrowLeftOnRectangle,
|
ArrowLeftOnRectangle,
|
||||||
Bookmark,
|
Bookmark,
|
||||||
|
ChevronUpDown,
|
||||||
Cog6Tooth,
|
Cog6Tooth,
|
||||||
ComputerDesktop,
|
ComputerDesktop,
|
||||||
|
Icon,
|
||||||
Identification,
|
Identification,
|
||||||
Inbox,
|
Inbox,
|
||||||
Moon,
|
Moon,
|
||||||
@@ -92,7 +94,7 @@
|
|||||||
: theme.colorScheme == 'light'
|
: theme.colorScheme == 'light'
|
||||||
? Sun
|
? Sun
|
||||||
: Moon}
|
: Moon}
|
||||||
class=" w-full"
|
class="w-full relative"
|
||||||
>
|
>
|
||||||
<Option value="system" class="hidden" icon={ComputerDesktop}>
|
<Option value="system" class="hidden" icon={ComputerDesktop}>
|
||||||
{$t('nav.menu.colorscheme.system')}
|
{$t('nav.menu.colorscheme.system')}
|
||||||
@@ -103,6 +105,7 @@
|
|||||||
<Option value="dark" class="hidden" icon={Moon}>
|
<Option value="dark" class="hidden" icon={Moon}>
|
||||||
{$t('nav.menu.colorscheme.dark')}
|
{$t('nav.menu.colorscheme.dark')}
|
||||||
</Option>
|
</Option>
|
||||||
|
<Icon micro size="16" src={ChevronUpDown} class="ml-auto" />
|
||||||
</SidebarButton>
|
</SidebarButton>
|
||||||
{/snippet}
|
{/snippet}
|
||||||
</Select>
|
</Select>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { HTMLAttributes } from 'svelte/elements'
|
import type { ClassValue, HTMLAttributes } from 'svelte/elements'
|
||||||
|
|
||||||
interface Props extends HTMLAttributes<HTMLSpanElement> {
|
interface Props extends HTMLAttributes<HTMLSpanElement> {
|
||||||
for?: string | undefined
|
for?: string | undefined
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
* The `text` prop will take precedence over the slot.
|
* The `text` prop will take precedence over the slot.
|
||||||
*/
|
*/
|
||||||
text?: string | undefined
|
text?: string | undefined
|
||||||
class?: string
|
class?: ClassValue
|
||||||
children?: import('svelte').Snippet
|
children?: import('svelte').Snippet
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -20,16 +20,14 @@
|
|||||||
}: Props = $props()
|
}: Props = $props()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:element
|
<label
|
||||||
this={forID ? 'label' : 'span'}
|
|
||||||
{...rest}
|
{...rest}
|
||||||
for={forID}
|
for={forID}
|
||||||
class="text-sm text-slate-800 dark:text-zinc-200 font-medium w-full {clazz ||
|
class={['text-sm text-slate-800 dark:text-zinc-200 font-medium', clazz]}
|
||||||
''}"
|
|
||||||
>
|
>
|
||||||
{#if text}
|
{#if text}
|
||||||
{text}
|
{text}
|
||||||
{:else if children}
|
{:else if children}
|
||||||
{@render children?.()}
|
{@render children?.()}
|
||||||
{/if}
|
{/if}
|
||||||
</svelte:element>
|
</label>
|
||||||
@@ -35,12 +35,14 @@
|
|||||||
|
|
||||||
<script lang="ts" generics="T">
|
<script lang="ts" generics="T">
|
||||||
import { setContext, tick, type Snippet } from 'svelte'
|
import { setContext, tick, type Snippet } from 'svelte'
|
||||||
|
import type { Placement } from 'svelte-floating-ui/core'
|
||||||
import {
|
import {
|
||||||
CheckCircle,
|
CheckCircle,
|
||||||
ChevronUpDown,
|
ChevronUpDown,
|
||||||
Icon,
|
Icon,
|
||||||
type IconSource,
|
type IconSource,
|
||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
|
import type { Attachment } from 'svelte/attachments'
|
||||||
import type { ClassValue, HTMLSelectAttributes } from 'svelte/elements'
|
import type { ClassValue, HTMLSelectAttributes } from 'svelte/elements'
|
||||||
import {
|
import {
|
||||||
buttonColor,
|
buttonColor,
|
||||||
@@ -52,9 +54,6 @@
|
|||||||
import Menu from '../../popover/Menu.svelte'
|
import Menu from '../../popover/Menu.svelte'
|
||||||
import MenuButton from '../../popover/MenuButton.svelte'
|
import MenuButton from '../../popover/MenuButton.svelte'
|
||||||
import Label from '../Label.svelte'
|
import Label from '../Label.svelte'
|
||||||
import { generateID } from '../helper.js'
|
|
||||||
import type { Placement } from 'svelte-floating-ui/core'
|
|
||||||
import type { Attachment } from 'svelte/attachments'
|
|
||||||
|
|
||||||
let open = $state(false)
|
let open = $state(false)
|
||||||
let element: HTMLSelectElement | undefined = $state()
|
let element: HTMLSelectElement | undefined = $state()
|
||||||
@@ -79,7 +78,6 @@
|
|||||||
label = undefined,
|
label = undefined,
|
||||||
size = 'md',
|
size = 'md',
|
||||||
shadow = 'none',
|
shadow = 'none',
|
||||||
id = generateID(),
|
|
||||||
class: clazz = '',
|
class: clazz = '',
|
||||||
baseClass = '',
|
baseClass = '',
|
||||||
selectClass = '',
|
selectClass = '',
|
||||||
@@ -89,16 +87,23 @@
|
|||||||
oncontextmenu,
|
oncontextmenu,
|
||||||
onchange,
|
onchange,
|
||||||
placement = 'bottom',
|
placement = 'bottom',
|
||||||
target,
|
target: passedTarget,
|
||||||
...rest
|
...rest
|
||||||
}: Props<T> = $props()
|
}: Props<T> = $props()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#snippet selectTarget(attachment: Attachment)}
|
{#snippet selectTarget(attachment: Attachment)}
|
||||||
|
<Label text={label} class={['space-y-1 relative', clazz, baseClass]}>
|
||||||
|
{@render customLabel?.()}
|
||||||
|
<Icon
|
||||||
|
src={ChevronUpDown}
|
||||||
|
micro
|
||||||
|
size="16"
|
||||||
|
class="absolute right-1.5 bottom-1 box-border pointer-events-none z-10 text-slate-600 dark:text-zinc-400"
|
||||||
|
/>
|
||||||
<select
|
<select
|
||||||
{@attach attachment}
|
{@attach attachment}
|
||||||
{...rest}
|
{...rest}
|
||||||
{id}
|
|
||||||
bind:this={element}
|
bind:this={element}
|
||||||
class={[
|
class={[
|
||||||
buttonSize[size],
|
buttonSize[size],
|
||||||
@@ -125,17 +130,14 @@
|
|||||||
{/if}
|
{/if}
|
||||||
{@render children?.()}
|
{@render children?.()}
|
||||||
</select>
|
</select>
|
||||||
|
</Label>
|
||||||
{/snippet}
|
{/snippet}
|
||||||
|
|
||||||
<div class={['flex flex-col gap-1', clazz, baseClass]}>
|
<Menu bind:open {placement}>
|
||||||
{#if customLabel || label}
|
{#snippet target(attachment)}
|
||||||
<Label for={id} text={label}>
|
{@const render = passedTarget ?? selectTarget}
|
||||||
{@render customLabel?.()}
|
{@render render?.(attachment)}
|
||||||
</Label>
|
{/snippet}
|
||||||
{/if}
|
|
||||||
|
|
||||||
<div class="w-full relative">
|
|
||||||
<Menu bind:open {placement} target={target ?? selectTarget}>
|
|
||||||
{#each context.options as option (option)}
|
{#each context.options as option (option)}
|
||||||
{#if customOption}{@render customOption({
|
{#if customOption}{@render customOption({
|
||||||
option,
|
option,
|
||||||
@@ -179,11 +181,3 @@
|
|||||||
{/if}
|
{/if}
|
||||||
{/each}
|
{/each}
|
||||||
</Menu>
|
</Menu>
|
||||||
<Icon
|
|
||||||
src={ChevronUpDown}
|
|
||||||
micro
|
|
||||||
size="16"
|
|
||||||
class="absolute right-0 top-1/4 mx-1.5 box-border pointer-events-none"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
@@ -14,7 +14,6 @@
|
|||||||
interface Props {
|
interface Props {
|
||||||
openOnHover?: boolean
|
openOnHover?: boolean
|
||||||
open?: boolean
|
open?: boolean
|
||||||
manual?: boolean
|
|
||||||
placement?: Placement
|
placement?: Placement
|
||||||
middleware?: Middleware[]
|
middleware?: Middleware[]
|
||||||
strategy?: Strategy
|
strategy?: Strategy
|
||||||
@@ -26,11 +25,9 @@
|
|||||||
let {
|
let {
|
||||||
openOnHover = false,
|
openOnHover = false,
|
||||||
open = $bindable(false),
|
open = $bindable(false),
|
||||||
manual = false,
|
|
||||||
placement = 'bottom-start',
|
placement = 'bottom-start',
|
||||||
middleware = [offset(6), shift({ padding: 6 }), flip()],
|
middleware = [offset(6), shift({ padding: 6 }), flip()],
|
||||||
strategy = 'absolute',
|
strategy = 'absolute',
|
||||||
class: clazz = '',
|
|
||||||
target,
|
target,
|
||||||
children,
|
children,
|
||||||
...rest
|
...rest
|
||||||
@@ -42,12 +39,10 @@
|
|||||||
{placement}
|
{placement}
|
||||||
{middleware}
|
{middleware}
|
||||||
{strategy}
|
{strategy}
|
||||||
{manual}
|
|
||||||
{target}
|
{target}
|
||||||
{...rest}
|
{...rest}
|
||||||
bind:open
|
bind:open
|
||||||
popoverClass="rounded-xl w-full backdrop-blur-md max-w-72"
|
popoverClass="rounded-xl w-full backdrop-blur-md max-w-72"
|
||||||
class={clazz}
|
|
||||||
>
|
>
|
||||||
{#snippet popover()}
|
{#snippet popover()}
|
||||||
<div
|
<div
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
type ButtonColor,
|
type ButtonColor,
|
||||||
type ButtonProps,
|
type ButtonProps,
|
||||||
} from '../button/Button.svelte'
|
} from '../button/Button.svelte'
|
||||||
import { Icon, type IconSource } from 'svelte-hero-icons'
|
import { ChevronRight, Icon, type IconSource } from 'svelte-hero-icons'
|
||||||
import type { ClassValue } from 'svelte/elements'
|
import type { ClassValue } from 'svelte/elements'
|
||||||
|
|
||||||
interface Props extends ButtonProps {
|
interface Props extends ButtonProps {
|
||||||
@@ -18,6 +18,7 @@
|
|||||||
prefix?: Snippet
|
prefix?: Snippet
|
||||||
children?: Snippet
|
children?: Snippet
|
||||||
suffix?: Snippet
|
suffix?: Snippet
|
||||||
|
nest?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
let {
|
let {
|
||||||
@@ -30,6 +31,7 @@
|
|||||||
prefix: passedPrefix,
|
prefix: passedPrefix,
|
||||||
children,
|
children,
|
||||||
suffix: passedSuffix,
|
suffix: passedSuffix,
|
||||||
|
nest,
|
||||||
...rest
|
...rest
|
||||||
}: Props = $props()
|
}: Props = $props()
|
||||||
</script>
|
</script>
|
||||||
@@ -48,6 +50,7 @@
|
|||||||
{alignment}
|
{alignment}
|
||||||
{href}
|
{href}
|
||||||
{disabled}
|
{disabled}
|
||||||
|
data-autoclose={nest ? 'false' : 'true'}
|
||||||
shadow="none"
|
shadow="none"
|
||||||
>
|
>
|
||||||
{#snippet prefix()}
|
{#snippet prefix()}
|
||||||
@@ -67,5 +70,8 @@
|
|||||||
{@render children?.()}
|
{@render children?.()}
|
||||||
{#snippet suffix()}
|
{#snippet suffix()}
|
||||||
{@render passedSuffix?.()}
|
{@render passedSuffix?.()}
|
||||||
|
{#if nest}
|
||||||
|
<Icon src={ChevronRight} size="16" micro class="ml-auto" />
|
||||||
|
{/if}
|
||||||
{/snippet}
|
{/snippet}
|
||||||
</Button>
|
</Button>
|
||||||
@@ -82,18 +82,15 @@
|
|||||||
const clickHandler = (event: Event) => {
|
const clickHandler = (event: Event) => {
|
||||||
if (!e) return
|
if (!e) return
|
||||||
|
|
||||||
if (!e?.contains(event.target as Node | null)) {
|
const target = event.target as Element | null
|
||||||
if (!autoClose) {
|
|
||||||
// @ts-expect-error svelte hell
|
if (!e?.contains(event.target as Element | null)) {
|
||||||
if (popoverEl && !popoverEl.contains(event.target)) {
|
if (target?.closest("[data-autoclose='false']") == null) {
|
||||||
open = false
|
open = false
|
||||||
}
|
|
||||||
} else {
|
|
||||||
open = false
|
|
||||||
}
|
|
||||||
document.removeEventListener('click', clickHandler)
|
document.removeEventListener('click', clickHandler)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
document.addEventListener('click', clickHandler)
|
document.addEventListener('click', clickHandler)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,9 +73,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</Header>
|
</Header>
|
||||||
|
|
||||||
<div class="mb-3 sm:mb-6">
|
<Select
|
||||||
<Select
|
class="relative w-max"
|
||||||
class=" w-max items-center"
|
|
||||||
bind:value={
|
bind:value={
|
||||||
() => data.unreadOnly.value.toString(),
|
() => data.unreadOnly.value.toString(),
|
||||||
v => (data.unreadOnly.value = v == 'true')
|
v => (data.unreadOnly.value = v == 'true')
|
||||||
@@ -87,17 +86,18 @@
|
|||||||
data.unreadOnly.value ? 'true' : 'false',
|
data.unreadOnly.value ? 'true' : 'false',
|
||||||
'page',
|
'page',
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{#snippet customLabel()}
|
{#snippet customLabel()}
|
||||||
<span class="flex items-center gap-1">
|
<div class="flex items-center gap-1">
|
||||||
<Icon src={Funnel} size="15" mini />
|
<Icon src={Funnel} size="15" mini />
|
||||||
{$t('filter.filter')}
|
{$t('filter.filter')}
|
||||||
</span>
|
</div>
|
||||||
{/snippet}
|
{/snippet}
|
||||||
<Option value="false">{$t('filter.location.all')}</Option>
|
<Option value="false">{$t('filter.location.all')}</Option>
|
||||||
<Option value="true">{$t('filter.unread')}</Option>
|
<Option value="true">{$t('filter.unread')}</Option>
|
||||||
</Select>
|
</Select>
|
||||||
</div>
|
|
||||||
|
<div class="h-3 sm:h-6"></div>
|
||||||
|
|
||||||
{#if !data.inbox?.value || (data.inbox.value?.length ?? 0) == 0}
|
{#if !data.inbox?.value || (data.inbox.value?.length ?? 0) == 0}
|
||||||
<Placeholder
|
<Placeholder
|
||||||
|
|||||||
Reference in new issue
Block a user