@stacksjs/components 0.2.368 → 0.2.370
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{Accordion-py9ntmst.stx → Accordion-ehpymjam.stx} +1 -1
- package/dist/{AccordionItem-asmsqxz9.stx → AccordionItem-fc4ekdqf.stx} +1 -1
- package/dist/{Button-tcjt3m8s.stx → Button-k2q6811a.stx} +1 -1
- package/dist/Combobox-9xh1jgjr.stx +266 -0
- package/dist/{ComboboxButton-g76stp1e.stx → ComboboxButton-4r6a45s1.stx} +8 -1
- package/dist/{ComboboxInput-4jcpvw7e.stx → ComboboxInput-1gyfpnca.stx} +4 -1
- package/dist/{ComboboxOption-vnb67p8d.stx → ComboboxOption-wkw70js7.stx} +27 -1
- package/dist/{ComboboxOptions-nbndbrxz.stx → ComboboxOptions-zhr9b6rx.stx} +1 -1
- package/dist/{CommandPalette-6rjcgske.stx → CommandPalette-vvaqtqat.stx} +3 -3
- package/dist/CommandPaletteItem-7290ce1z.stx +40 -0
- package/dist/{DefaultPaymentMethod-r0hcjajr.stx → DefaultPaymentMethod-ss3x61tr.stx} +1 -1
- package/dist/{Drawer-jcdj3qk2.stx → Drawer-hc0jjpsw.stx} +1 -1
- package/dist/Dropdown-25160tc6.stx +204 -0
- package/dist/{DropdownButton-tx9hb2de.stx → DropdownButton-wxc25hsy.stx} +3 -1
- package/dist/{DropdownItem-wht1vcm5.stx → DropdownItem-af0vzc8a.stx} +15 -1
- package/dist/{DropdownItems-v12h6zpf.stx → DropdownItems-bkz7jkyz.stx} +1 -1
- package/dist/Listbox-32gzxace.stx +273 -0
- package/dist/{ListboxButton-t43pp03e.stx → ListboxButton-gan8e3nw.stx} +3 -1
- package/dist/{ListboxOption-9c9jpz1n.stx → ListboxOption-gpaqvk3s.stx} +14 -1
- package/dist/{ListboxOptions-qxrkrb8z.stx → ListboxOptions-2928864k.stx} +1 -1
- package/dist/{Login-j3pc04ka.stx → Login-3dsk93vm.stx} +4 -4
- package/dist/{Notification-7wgk0sw6.stx → Notification-2ws4ym4s.stx} +2 -2
- package/dist/{Pagination-z9jxnaeq.stx → Pagination-330ybzf1.stx} +2 -2
- package/dist/Popover-9m42pym0.stx +101 -0
- package/dist/{PopoverButton-70th24xc.stx → PopoverButton-3w6550hv.stx} +2 -1
- package/dist/{PopoverPanel-7771yf35.stx → PopoverPanel-d84gk1w1.stx} +1 -1
- package/dist/{RadioGroup-hzz4xep9.stx → RadioGroup-smqcqgds.stx} +15 -2
- package/dist/{RadioGroupOption-7fcgfsah.stx → RadioGroupOption-twcw1b2a.stx} +14 -2
- package/dist/{Select-sbr8dqzn.stx → Select-danh680d.stx} +1 -1
- package/dist/{Signup-77y9ea7t.stx → Signup-dh96kskd.stx} +2 -2
- package/dist/{StepperStep-34kwv0t0.stx → StepperStep-b78wmshd.stx} +1 -1
- package/dist/{SubscriptionCheckout-pggq5a4k.stx → SubscriptionCheckout-n3btqrzk.stx} +2 -2
- package/dist/{Switch-fxbw7s16.stx → Switch-27hp6pq5.stx} +1 -1
- package/dist/{TabBarItem-wv2r8496.stx → TabBarItem-kddfnhk3.stx} +1 -1
- package/dist/{Tabs-51vr631j.stx → Tabs-f1n3ggkw.stx} +1 -1
- package/dist/{TwoFactorChallenge-28px8pyk.stx → TwoFactorChallenge-ete7yk9y.stx} +1 -1
- package/dist/index.js +7 -7
- package/package.json +3 -3
- package/src/components/Footer.stx +2 -2
- package/src/components/Hero.stx +1 -1
- package/src/ui/accordion/Accordion.stx +1 -1
- package/src/ui/accordion/AccordionItem.stx +1 -1
- package/src/ui/auth/Login.stx +4 -4
- package/src/ui/auth/Signup.stx +2 -2
- package/src/ui/auth/TwoFactorChallenge.stx +1 -1
- package/src/ui/button/Button.stx +1 -1
- package/src/ui/combobox/Combobox.stx +174 -4
- package/src/ui/combobox/ComboboxButton.stx +8 -1
- package/src/ui/combobox/ComboboxInput.stx +4 -1
- package/src/ui/combobox/ComboboxOption.stx +27 -1
- package/src/ui/combobox/ComboboxOptions.stx +1 -1
- package/src/ui/command-palette/CommandPalette.stx +3 -3
- package/src/ui/command-palette/CommandPaletteItem.stx +14 -1
- package/src/ui/drawer/Drawer.stx +1 -1
- package/src/ui/dropdown/Dropdown.stx +122 -0
- package/src/ui/dropdown/DropdownButton.stx +3 -1
- package/src/ui/dropdown/DropdownItem.stx +15 -1
- package/src/ui/dropdown/DropdownItems.stx +1 -1
- package/src/ui/listbox/Listbox.stx +175 -3
- package/src/ui/listbox/ListboxButton.stx +3 -1
- package/src/ui/listbox/ListboxOption.stx +14 -1
- package/src/ui/listbox/ListboxOptions.stx +1 -1
- package/src/ui/mobile/TabBarItem.stx +1 -1
- package/src/ui/notification/Notification.stx +2 -2
- package/src/ui/pagination/Pagination.stx +2 -2
- package/src/ui/payment/DefaultPaymentMethod.stx +1 -1
- package/src/ui/payment/SubscriptionCheckout.stx +2 -2
- package/src/ui/popover/Popover.stx +43 -2
- package/src/ui/popover/PopoverButton.stx +2 -1
- package/src/ui/popover/PopoverPanel.stx +1 -1
- package/src/ui/radio-group/RadioGroup.stx +15 -2
- package/src/ui/radio-group/RadioGroupOption.stx +14 -2
- package/src/ui/select/Select.stx +1 -1
- package/src/ui/stepper/StepperStep.stx +1 -1
- package/src/ui/switch/Switch.stx +1 -1
- package/src/ui/tabs/Tabs.stx +1 -1
- package/dist/Combobox-06x0nywb.stx +0 -96
- package/dist/CommandPaletteItem-6rp133ta.stx +0 -27
- package/dist/Dropdown-cmwge7vx.stx +0 -82
- package/dist/Listbox-e5jreb0a.stx +0 -101
- package/dist/Popover-3g8rgxt1.stx +0 -60
|
@@ -12,7 +12,7 @@ export const defaultOpen = $props.defaultOpen || []
|
|
|
12
12
|
export const className = $props.className || ''
|
|
13
13
|
|
|
14
14
|
export const accordionClasses = `divide-y divide-line border border-line rounded-panel ${className}`.trim()
|
|
15
|
-
export const headerClasses = `w-full flex items-center justify-between px-4 py-3 text-left font-medium text-fg hover:bg-surface-hover transition-colors duration-150 focus:outline-none focus:ring-2 focus:ring-accent
|
|
15
|
+
export const headerClasses = `w-full flex items-center justify-between px-4 py-3 text-left font-medium text-fg hover:bg-surface-hover transition-colors duration-150 focus:outline-none focus:ring-2 focus:ring-accent focus:ring-offset-2 focus:ring-offset-panel`.trim()
|
|
16
16
|
export const iconClasses = `w-5 h-5 text-fg-soft transition-transform duration-200`.trim()
|
|
17
17
|
export const contentClasses = `px-4 py-3 text-fg-strong`.trim()
|
|
18
18
|
export const hasPropItems = Array.isArray(items) && items.length > 0
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
export const title = $props.title || ''
|
|
8
8
|
export const className = $props.className || ''
|
|
9
9
|
|
|
10
|
-
const headerClasses = 'w-full flex items-center justify-between px-4 py-3 text-left font-medium text-fg hover:bg-surface-hover transition-colors duration-150 focus:outline-none focus:ring-2 focus:ring-accent
|
|
10
|
+
const headerClasses = 'w-full flex items-center justify-between px-4 py-3 text-left font-medium text-fg hover:bg-surface-hover transition-colors duration-150 focus:outline-none focus:ring-2 focus:ring-accent focus:ring-offset-2 focus:ring-offset-panel'
|
|
11
11
|
const iconClasses = 'w-5 h-5 text-fg-soft transition-transform duration-200'
|
|
12
12
|
const contentClasses = 'px-4 py-3 text-fg-strong'
|
|
13
13
|
</script>
|
package/src/ui/auth/Login.stx
CHANGED
|
@@ -106,7 +106,7 @@ function onSubmit(event) {
|
|
|
106
106
|
|
|
107
107
|
@if(showForgotPassword)
|
|
108
108
|
<div class="text-sm leading-6">
|
|
109
|
-
<StxLink to="{{ forgotPasswordHref }}" class="text-
|
|
109
|
+
<StxLink to="{{ forgotPasswordHref }}" class="text-link font-semibold hover:text-link-hover">
|
|
110
110
|
Forgot password?
|
|
111
111
|
</StxLink>
|
|
112
112
|
</div>
|
|
@@ -140,7 +140,7 @@ function onSubmit(event) {
|
|
|
140
140
|
<button
|
|
141
141
|
type="button"
|
|
142
142
|
@click="onSocial('google')"
|
|
143
|
-
class="w-full flex items-center justify-center gap-3 rounded-control bg-field px-3 py-2 text-sm text-fg font-semibold shadow-sm ring-1 ring-line-strong ring-inset hover:bg-field-hover focus-visible:ring-
|
|
143
|
+
class="w-full flex items-center justify-center gap-3 rounded-control bg-field px-3 py-2 text-sm text-fg font-semibold shadow-sm ring-1 ring-line-strong ring-inset hover:bg-field-hover focus-visible:ring-2 focus-visible:ring-accent"
|
|
144
144
|
>
|
|
145
145
|
<svg class="h-5 w-5" viewBox="0 0 24 24" aria-hidden="true">
|
|
146
146
|
<path d="M12.0003 4.75C13.7703 4.75 15.3553 5.36002 16.6053 6.54998L20.0303 3.125C17.9502 1.19 15.2353 0 12.0003 0C7.31028 0 3.25527 2.69 1.28027 6.60998L5.27028 9.70498C6.21525 6.86002 8.87028 4.75 12.0003 4.75Z" fill="#EA4335" />
|
|
@@ -154,7 +154,7 @@ function onSubmit(event) {
|
|
|
154
154
|
<button
|
|
155
155
|
type="button"
|
|
156
156
|
@click="onSocial('github')"
|
|
157
|
-
class="w-full flex items-center justify-center gap-3 rounded-control bg-field px-3 py-2 text-sm text-fg font-semibold shadow-sm ring-1 ring-line-strong ring-inset hover:bg-field-hover focus-visible:ring-
|
|
157
|
+
class="w-full flex items-center justify-center gap-3 rounded-control bg-field px-3 py-2 text-sm text-fg font-semibold shadow-sm ring-1 ring-line-strong ring-inset hover:bg-field-hover focus-visible:ring-2 focus-visible:ring-accent"
|
|
158
158
|
>
|
|
159
159
|
<svg class="h-5 w-5 fill-[#24292F]" fill="currentColor" viewBox="0 0 20 20" aria-hidden="true">
|
|
160
160
|
<path fill-rule="evenodd" d="M10 0C4.477 0 0 4.484 0 10.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0110 4.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.203 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.942.359.31.678.921.678 1.856 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0020 10.017C20 4.484 15.522 0 10 0z" clip-rule="evenodd" />
|
|
@@ -169,7 +169,7 @@ function onSubmit(event) {
|
|
|
169
169
|
@if(showSignup)
|
|
170
170
|
<p class="mt-10 text-center text-sm text-fg-soft">
|
|
171
171
|
Not a member?
|
|
172
|
-
<StxLink to="{{ signupHref }}" class="text-
|
|
172
|
+
<StxLink to="{{ signupHref }}" class="text-link font-semibold leading-6 hover:text-link-hover">
|
|
173
173
|
{{ signupText }}
|
|
174
174
|
</StxLink>
|
|
175
175
|
</p>
|
package/src/ui/auth/Signup.stx
CHANGED
|
@@ -140,7 +140,7 @@ function onSubmit(event) {
|
|
|
140
140
|
<button
|
|
141
141
|
type="button"
|
|
142
142
|
@click="onSocial('google')"
|
|
143
|
-
class="w-full flex items-center justify-center gap-3 rounded-control bg-field px-3 py-2 text-sm text-fg font-semibold shadow-sm ring-1 ring-line-strong ring-inset hover:bg-field-hover focus-visible:ring-
|
|
143
|
+
class="w-full flex items-center justify-center gap-3 rounded-control bg-field px-3 py-2 text-sm text-fg font-semibold shadow-sm ring-1 ring-line-strong ring-inset hover:bg-field-hover focus-visible:ring-2 focus-visible:ring-accent"
|
|
144
144
|
>
|
|
145
145
|
<svg class="h-5 w-5" viewBox="0 0 24 24" aria-hidden="true">
|
|
146
146
|
<path d="M12.0003 4.75C13.7703 4.75 15.3553 5.36002 16.6053 6.54998L20.0303 3.125C17.9502 1.19 15.2353 0 12.0003 0C7.31028 0 3.25527 2.69 1.28027 6.60998L5.27028 9.70498C6.21525 6.86002 8.87028 4.75 12.0003 4.75Z" fill="#EA4335" />
|
|
@@ -154,7 +154,7 @@ function onSubmit(event) {
|
|
|
154
154
|
<button
|
|
155
155
|
type="button"
|
|
156
156
|
@click="onSocial('github')"
|
|
157
|
-
class="w-full flex items-center justify-center gap-3 rounded-control bg-field px-3 py-2 text-sm text-fg font-semibold shadow-sm ring-1 ring-line-strong ring-inset hover:bg-field-hover focus-visible:ring-
|
|
157
|
+
class="w-full flex items-center justify-center gap-3 rounded-control bg-field px-3 py-2 text-sm text-fg font-semibold shadow-sm ring-1 ring-line-strong ring-inset hover:bg-field-hover focus-visible:ring-2 focus-visible:ring-accent"
|
|
158
158
|
>
|
|
159
159
|
<svg class="h-5 w-5 fill-[#24292F] dark:fill-white" fill="currentColor" viewBox="0 0 20 20" aria-hidden="true">
|
|
160
160
|
<path fill-rule="evenodd" d="M10 0C4.477 0 0 4.484 0 10.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0110 4.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.203 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.942.359.31.678.921.678 1.856 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0020 10.017C20 4.484 15.522 0 10 0z" clip-rule="evenodd" />
|
|
@@ -80,7 +80,7 @@ function onRecoveryCode(event) {
|
|
|
80
80
|
<div class="py-4">
|
|
81
81
|
<button
|
|
82
82
|
type="submit"
|
|
83
|
-
class="relative h-8 w-full flex items-center justify-center rounded-full bg-accent-solid px-4 text-accent-ink font-semibold hover:bg-accent-solid-hover focus:outline-none focus:ring-2 focus:ring-accent focus:ring-offset-2"
|
|
83
|
+
class="relative h-8 w-full flex items-center justify-center rounded-full bg-accent-solid px-4 text-accent-ink font-semibold hover:bg-accent-solid-hover focus:outline-none focus:ring-2 focus:ring-accent focus:ring-offset-2 focus:ring-offset-panel"
|
|
84
84
|
>
|
|
85
85
|
Verify
|
|
86
86
|
</button>
|
package/src/ui/button/Button.stx
CHANGED
|
@@ -87,7 +87,7 @@ const iconSizeClasses = { xs: 'h-3 w-3', sm: 'h-4 w-4', md: 'h-5 w-5', lg: 'h-6
|
|
|
87
87
|
* the token's light value is that same blue-500 and its dark value is a step
|
|
88
88
|
* darker, which is a ring that was missing rather than one that changed.
|
|
89
89
|
*/
|
|
90
|
-
const baseClasses = 'inline-flex items-center justify-center font-semibold rounded-control transition-all duration-200 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-
|
|
90
|
+
const baseClasses = 'inline-flex items-center justify-center font-semibold rounded-control transition-all duration-200 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-panel focus:ring-accent disabled:opacity-50 disabled:cursor-not-allowed disabled:pointer-events-none'
|
|
91
91
|
const widthClasses = fullWidth ? 'w-full' : ''
|
|
92
92
|
export const isDisabled = disabled || loading
|
|
93
93
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script server>
|
|
2
2
|
export const value = $props.value
|
|
3
|
+
export const valueJson = JSON.stringify(value === undefined ? null : value)
|
|
3
4
|
export const className = $props.className || ''
|
|
4
5
|
export const as = $props.as || 'div'
|
|
5
6
|
|
|
@@ -11,11 +12,33 @@ export const comboboxInstanceId = $uid
|
|
|
11
12
|
<script client>
|
|
12
13
|
const emit = defineEmits()
|
|
13
14
|
const comboboxInstanceId = {{ comboboxInstanceId }}
|
|
14
|
-
|
|
15
|
+
/*
|
|
16
|
+
* JSON built on the server and emitted raw, rather than a 'null' sentinel
|
|
17
|
+
* through an ordinary interpolation.
|
|
18
|
+
*
|
|
19
|
+
* A `value === undefined ? 'null' : value` ternary was meant to put the bare
|
|
20
|
+
* token null into the script. An interpolation QUOTES a string, so what it
|
|
21
|
+
* emitted was the four-character string "null" -- truthy, in the one place a
|
|
22
|
+
* value is meant to be absent. JSON.stringify produces the correct literal for
|
|
23
|
+
* every type, null included, and raw interpolation passes it through unquoted.
|
|
24
|
+
* Calendar and DateRangePicker already avoid this sentinel and say why
|
|
25
|
+
* (stacksjs/stx#1981).
|
|
26
|
+
*/
|
|
27
|
+
const initialValue = {!! valueJson !!}
|
|
15
28
|
|
|
16
29
|
const isOpen = state(false)
|
|
17
30
|
const selected = state(initialValue)
|
|
18
31
|
const query = state('')
|
|
32
|
+
/*
|
|
33
|
+
* The ACTIVE option, which is not the focused one.
|
|
34
|
+
*
|
|
35
|
+
* A combobox keeps focus in its input so the user can keep typing, so there is
|
|
36
|
+
* no focused option to move -- the active one is named by
|
|
37
|
+
* `aria-activedescendant` on the input instead. That is why <Listbox> and
|
|
38
|
+
* <Dropdown> move real focus with a roving tabindex and this does not, and why
|
|
39
|
+
* aria-activedescendant was absent until there was something to point it at.
|
|
40
|
+
*/
|
|
41
|
+
const activeIndex = state(-1)
|
|
19
42
|
let rootEl = null
|
|
20
43
|
let outsideHandler = null
|
|
21
44
|
|
|
@@ -27,6 +50,7 @@ function selectValue(v) {
|
|
|
27
50
|
selected.set(v)
|
|
28
51
|
isOpen.set(false)
|
|
29
52
|
syncOptionStates()
|
|
53
|
+
syncExpanded()
|
|
30
54
|
emit('change', v)
|
|
31
55
|
}
|
|
32
56
|
|
|
@@ -44,8 +68,124 @@ function syncOptionStates() {
|
|
|
44
68
|
}
|
|
45
69
|
}
|
|
46
70
|
|
|
47
|
-
|
|
48
|
-
|
|
71
|
+
/*
|
|
72
|
+
* role="combobox" makes aria-expanded REQUIRED, and the state lived only in
|
|
73
|
+
* `data-state` on the root. Nothing announced whether the list was showing.
|
|
74
|
+
*
|
|
75
|
+
* aria-activedescendant is deliberately absent: it names the option a user has
|
|
76
|
+
* moved to, and this combobox has no option keyboard navigation to move with,
|
|
77
|
+
* so pointing at one would describe a focus that does not exist.
|
|
78
|
+
*/
|
|
79
|
+
function syncExpanded() {
|
|
80
|
+
if (!rootEl) return
|
|
81
|
+
const input = rootEl.querySelector('[data-stx-combobox-input]')
|
|
82
|
+
if (!input) return
|
|
83
|
+
input.setAttribute('aria-expanded', isOpen() ? 'true' : 'false')
|
|
84
|
+
const list = rootEl.querySelector('[data-stx-combobox-options]')
|
|
85
|
+
if (!list) return
|
|
86
|
+
if (!list.id) list.id = 'stx-combobox-list-' + comboboxInstanceId
|
|
87
|
+
input.setAttribute('aria-controls', list.id)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function optionElements() {
|
|
91
|
+
if (!rootEl) return []
|
|
92
|
+
const all = rootEl.querySelectorAll('[data-stx-combobox-option]')
|
|
93
|
+
return Array.prototype.filter.call(all, option => option.getAttribute('aria-disabled') !== 'true')
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/*
|
|
97
|
+
* aria-activedescendant needs an id to point at, so the options are given one
|
|
98
|
+
* here rather than in the markup: the component does not know its own index
|
|
99
|
+
* and an id has to be unique on the page, not just within the list.
|
|
100
|
+
*/
|
|
101
|
+
function syncActiveOption() {
|
|
102
|
+
if (!rootEl) return
|
|
103
|
+
const options = optionElements()
|
|
104
|
+
const index = activeIndex()
|
|
105
|
+
const doc = rootEl.ownerDocument
|
|
106
|
+
for (let i = 0; i < options.length; i++) {
|
|
107
|
+
/*
|
|
108
|
+
* An id is only usable here if it is UNIQUE, and an existing one may not
|
|
109
|
+
* be: event binding stamps every bound element `__stx_evt_0`, restarting
|
|
110
|
+
* per component render, so four options arrive sharing one id and
|
|
111
|
+
* getElementById returns an arbitrary one of them. An author's own id is
|
|
112
|
+
* kept when it really is unique; otherwise this assigns its own.
|
|
113
|
+
*/
|
|
114
|
+
const existing = options[i].id
|
|
115
|
+
const unique = existing && doc.querySelectorAll('[id="' + existing + '"]').length === 1
|
|
116
|
+
if (!unique) options[i].id = 'stx-combobox-option-' + comboboxInstanceId + '-' + i
|
|
117
|
+
if (i === index) options[i].setAttribute('data-active', 'true')
|
|
118
|
+
else options[i].removeAttribute('data-active')
|
|
119
|
+
}
|
|
120
|
+
const input = rootEl.querySelector('[data-stx-combobox-input]')
|
|
121
|
+
if (!input) return
|
|
122
|
+
const active = index >= 0 ? options[index] : null
|
|
123
|
+
if (active) input.setAttribute('aria-activedescendant', active.id)
|
|
124
|
+
else input.removeAttribute('aria-activedescendant')
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function moveActive(delta) {
|
|
128
|
+
const options = optionElements()
|
|
129
|
+
if (!options.length) return
|
|
130
|
+
const from = activeIndex()
|
|
131
|
+
const next = from < 0
|
|
132
|
+
? (delta > 0 ? 0 : options.length - 1)
|
|
133
|
+
: (from + delta + options.length) % options.length
|
|
134
|
+
activeIndex.set(next)
|
|
135
|
+
syncActiveOption()
|
|
136
|
+
const landed = optionElements()[next]
|
|
137
|
+
// The list scrolls at max-h-60, so an option stepped past the fold has to be
|
|
138
|
+
// brought in: there is no focus move to do it for us.
|
|
139
|
+
if (landed && landed.scrollIntoView) landed.scrollIntoView({ block: 'nearest' })
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/*
|
|
143
|
+
* Gated on the event coming from inside this combobox, like the Escape
|
|
144
|
+
* handler, so an arrow key elsewhere on the page still scrolls it.
|
|
145
|
+
*
|
|
146
|
+
* Space is deliberately absent. On <Listbox> and <Dropdown> it activates the
|
|
147
|
+
* focused item; here focus is in a text input and Space has to type a space.
|
|
148
|
+
*/
|
|
149
|
+
function onComboboxKey(event) {
|
|
150
|
+
if (!rootEl || !rootEl.contains(event.target)) return
|
|
151
|
+
const key = event.key
|
|
152
|
+
|
|
153
|
+
if (!isOpen()) {
|
|
154
|
+
if (key !== 'ArrowDown' && key !== 'ArrowUp') return
|
|
155
|
+
event.preventDefault()
|
|
156
|
+
open()
|
|
157
|
+
activeIndex.set(-1)
|
|
158
|
+
moveActive(key === 'ArrowDown' ? 1 : -1)
|
|
159
|
+
return
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (key === 'ArrowDown' || key === 'ArrowUp') {
|
|
163
|
+
event.preventDefault()
|
|
164
|
+
moveActive(key === 'ArrowDown' ? 1 : -1)
|
|
165
|
+
return
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (key === 'Home' || key === 'End') {
|
|
169
|
+
event.preventDefault()
|
|
170
|
+
activeIndex.set(-1)
|
|
171
|
+
moveActive(key === 'Home' ? 1 : -1)
|
|
172
|
+
return
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (key === 'Enter') {
|
|
176
|
+
const options = optionElements()
|
|
177
|
+
const index = activeIndex()
|
|
178
|
+
if (index < 0 || !options[index]) return
|
|
179
|
+
event.preventDefault()
|
|
180
|
+
options[index].click()
|
|
181
|
+
return
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (key === 'Tab') close()
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function open() { if (!isOpen()) { isOpen.set(true); syncExpanded() } }
|
|
188
|
+
function close() { if (isOpen()) { isOpen.set(false); activeIndex.set(-1); syncActiveOption(); syncExpanded() } }
|
|
49
189
|
function toggle() { isOpen() ? close() : open() }
|
|
50
190
|
|
|
51
191
|
function onToggle(event) { event.stopPropagation(); toggle() }
|
|
@@ -53,27 +193,57 @@ function onSelect(event) { event.stopPropagation(); selectValue(event.detail) }
|
|
|
53
193
|
function onQuery(event) {
|
|
54
194
|
event.stopPropagation()
|
|
55
195
|
query.set(event.detail)
|
|
196
|
+
// The list the indexes referred to is about to change under them.
|
|
197
|
+
activeIndex.set(-1)
|
|
198
|
+
syncActiveOption()
|
|
56
199
|
if (!isOpen()) open()
|
|
57
200
|
emit('query', event.detail)
|
|
58
201
|
}
|
|
59
202
|
|
|
203
|
+
/*
|
|
204
|
+
* Escape dismisses it, from anywhere rather than only from inside the panel.
|
|
205
|
+
*
|
|
206
|
+
* Opening one of these does not move focus, so a keydown bound on the panel
|
|
207
|
+
* never sees the first Escape - focus is still on whatever opened it. Drawer
|
|
208
|
+
* reached the same conclusion and binds on the document; this follows it, and
|
|
209
|
+
* only acts while open so one open popup does not swallow Escape for the page.
|
|
210
|
+
*
|
|
211
|
+
* Focus goes back to the trigger, but only if it had moved into the panel:
|
|
212
|
+
* otherwise this would steal it from wherever the user actually is.
|
|
213
|
+
*/
|
|
214
|
+
function onDocumentKey(event) {
|
|
215
|
+
if (event.key !== 'Escape' || !isOpen()) return
|
|
216
|
+
close()
|
|
217
|
+
if (!rootEl) return
|
|
218
|
+
const active = rootEl.ownerDocument && rootEl.ownerDocument.activeElement
|
|
219
|
+
if (!active || !rootEl.contains(active)) return
|
|
220
|
+
// The input is the tab stop here; the chevron is deliberately tabindex="-1".
|
|
221
|
+
const trigger = rootEl.querySelector('[data-stx-combobox-input]')
|
|
222
|
+
if (trigger && trigger.focus) trigger.focus()
|
|
223
|
+
}
|
|
224
|
+
|
|
60
225
|
onMount(() => {
|
|
61
226
|
rootEl = document.querySelector(`[data-combobox-id="${comboboxInstanceId}"]`)
|
|
62
227
|
syncOptionStates()
|
|
228
|
+
syncExpanded()
|
|
63
229
|
outsideHandler = (event) => {
|
|
64
230
|
if (!isOpen()) return
|
|
65
231
|
if (rootEl && !rootEl.contains(event.target)) close()
|
|
66
232
|
}
|
|
67
233
|
document.addEventListener('click', outsideHandler, true)
|
|
234
|
+
document.addEventListener('keydown', onDocumentKey)
|
|
235
|
+
document.addEventListener('keydown', onComboboxKey)
|
|
68
236
|
})
|
|
69
237
|
|
|
70
238
|
onDestroy(() => {
|
|
71
239
|
if (outsideHandler) document.removeEventListener('click', outsideHandler, true)
|
|
240
|
+
document.removeEventListener('keydown', onDocumentKey)
|
|
241
|
+
document.removeEventListener('keydown', onComboboxKey)
|
|
72
242
|
})
|
|
73
243
|
|
|
74
244
|
const dataState = derived(() => isOpen() ? 'open' : 'closed')
|
|
75
245
|
|
|
76
|
-
defineExpose({ isOpen, selected, query, toggle, open, close, selectValue })
|
|
246
|
+
defineExpose({ isOpen, selected, query, activeIndex, toggle, open, close, selectValue })
|
|
77
247
|
</script>
|
|
78
248
|
|
|
79
249
|
<component
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
<script server>
|
|
2
2
|
export const className = $props.className || ''
|
|
3
3
|
export const as = $props.as || 'button'
|
|
4
|
+
/*
|
|
5
|
+
* An icon-only control needs a name. It is not in the tab order (APG puts the
|
|
6
|
+
* combobox itself there and gives this button tabindex="-1"), but a screen
|
|
7
|
+
* reader still reaches it in browse mode, where it announced "button".
|
|
8
|
+
*/
|
|
9
|
+
export const label = $props.label || 'Show options'
|
|
4
10
|
|
|
5
11
|
const baseClasses = 'absolute inset-y-0 right-0 flex items-center pr-2'
|
|
6
12
|
export const buttonClasses = `${baseClasses} ${className}`.trim()
|
|
@@ -17,9 +23,10 @@ function onClick(event) {
|
|
|
17
23
|
class="{{ buttonClasses }}"
|
|
18
24
|
data-stx-combobox-button
|
|
19
25
|
tabindex="-1"
|
|
26
|
+
aria-label="{{ label }}"
|
|
20
27
|
@click="onClick($event)"
|
|
21
28
|
>
|
|
22
|
-
<svg class="h-5 w-5 text-
|
|
29
|
+
<svg class="h-5 w-5 text-fg-soft" aria-hidden="true" viewBox="0 0 20 20" fill="none" stroke="currentColor">
|
|
23
30
|
<path d="M7 7l3-3 3 3m0 6l-3 3-3-3" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" />
|
|
24
31
|
</svg>
|
|
25
32
|
</component>
|
|
@@ -4,7 +4,7 @@ export const className = $props.className || ''
|
|
|
4
4
|
export const placeholder = $props.placeholder || ''
|
|
5
5
|
export const disabled = $bool($props.disabled)
|
|
6
6
|
|
|
7
|
-
const baseClasses = 'w-full rounded-panel border-none bg-panel py-2 pl-3 pr-10 text-sm leading-5 text-fg focus:ring-0 focus:outline-none focus-visible:border-accent-solid focus-visible:ring-2 focus-visible:ring-accent
|
|
7
|
+
const baseClasses = 'w-full rounded-panel border-none bg-panel py-2 pl-3 pr-10 text-sm leading-5 text-fg focus:ring-0 focus:outline-none focus-visible:border-accent-solid focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-panel focus-visible:ring-offset-2'
|
|
8
8
|
const disabledClasses = disabled ? 'opacity-50 cursor-not-allowed' : ''
|
|
9
9
|
export const inputClasses = `${baseClasses} ${disabledClasses} ${className}`.trim()
|
|
10
10
|
</script>
|
|
@@ -24,6 +24,9 @@ function onInput(event) {
|
|
|
24
24
|
type="text"
|
|
25
25
|
class="{{ inputClasses }}"
|
|
26
26
|
data-stx-combobox-input
|
|
27
|
+
role="combobox"
|
|
28
|
+
aria-expanded="false"
|
|
29
|
+
aria-autocomplete="list"
|
|
27
30
|
placeholder="{{ placeholder }}"
|
|
28
31
|
value="{{ displayValue }}"
|
|
29
32
|
@if(disabled)disabled@endif
|
|
@@ -12,7 +12,19 @@ export const valueJson = JSON.stringify(value === undefined ? null : value)
|
|
|
12
12
|
|
|
13
13
|
<script client>
|
|
14
14
|
const isDisabled = {{ disabled }}
|
|
15
|
-
|
|
15
|
+
/*
|
|
16
|
+
* JSON built on the server and emitted raw, rather than a 'null' sentinel
|
|
17
|
+
* through an ordinary interpolation.
|
|
18
|
+
*
|
|
19
|
+
* A `value === undefined ? 'null' : value` ternary was meant to put the bare
|
|
20
|
+
* token null into the script. An interpolation QUOTES a string, so what it
|
|
21
|
+
* emitted was the four-character string "null" -- truthy, in the one place a
|
|
22
|
+
* value is meant to be absent. JSON.stringify produces the correct literal for
|
|
23
|
+
* every type, null included, and raw interpolation passes it through unquoted.
|
|
24
|
+
* Calendar and DateRangePicker already avoid this sentinel and say why
|
|
25
|
+
* (stacksjs/stx#1981).
|
|
26
|
+
*/
|
|
27
|
+
const optionValue = {!! valueJson !!}
|
|
16
28
|
|
|
17
29
|
function onClick(event) {
|
|
18
30
|
if (isDisabled) return
|
|
@@ -42,6 +54,20 @@ function onClick(event) {
|
|
|
42
54
|
</component>
|
|
43
55
|
|
|
44
56
|
<style>
|
|
57
|
+
/*
|
|
58
|
+
* The ACTIVE option, highlighted to match the hover state.
|
|
59
|
+
*
|
|
60
|
+
* A combobox keeps focus in its input, so the option a user has arrowed to has
|
|
61
|
+
* no focus ring to show it -- `aria-activedescendant` tells a screen reader
|
|
62
|
+
* which one it is and nothing told a sighted keyboard user. Written out rather
|
|
63
|
+
* than as a utility class because the runtime sets a data attribute, and it
|
|
64
|
+
* resolves through the same role variable `hover:bg-accent-soft` compiles to,
|
|
65
|
+
* so re-pointing the accent moves both together.
|
|
66
|
+
*/
|
|
67
|
+
[data-stx-combobox-option][data-active="true"] {
|
|
68
|
+
background-color: var(--stx-accent-soft, oklch(93.2% 0.032 255.585));
|
|
69
|
+
}
|
|
70
|
+
|
|
45
71
|
[data-stx-combobox-option][data-selected="false"] [data-stx-combobox-check],
|
|
46
72
|
[data-stx-combobox-option]:not([data-selected]) [data-stx-combobox-check] {
|
|
47
73
|
display: none;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
export const className = $props.className || ''
|
|
3
3
|
export const as = $props.as || 'ul'
|
|
4
4
|
|
|
5
|
-
const baseClasses = 'absolute z-10 mt-1 max-h-60 w-full overflow-auto rounded-panel bg-panel py-1 text-base shadow-lg ring-1 ring-
|
|
5
|
+
const baseClasses = 'absolute z-10 mt-1 max-h-60 w-full overflow-auto rounded-panel bg-panel py-1 text-base shadow-lg ring-1 ring-line focus:outline-none'
|
|
6
6
|
export const optionsClasses = `${baseClasses} ${className}`.trim()
|
|
7
7
|
</script>
|
|
8
8
|
|
|
@@ -60,14 +60,14 @@ defineExpose({ isOpen, query, show, close })
|
|
|
60
60
|
>
|
|
61
61
|
<div class="fixed inset-0 bg-neutral-500/25 dark:bg-neutral-500/50 transition-opacity" @click="close()"></div>
|
|
62
62
|
|
|
63
|
-
<div class="mx-auto max-w-xl transform divide-y divide-line overflow-hidden rounded-xl bg-panel shadow-2xl ring-1 ring-
|
|
63
|
+
<div class="mx-auto max-w-xl transform divide-y divide-line overflow-hidden rounded-xl bg-panel shadow-2xl ring-1 ring-line transition-all relative">
|
|
64
64
|
<div class="relative">
|
|
65
|
-
<svg class="pointer-events-none absolute top-3.5 left-4 h-5 w-5 text-
|
|
65
|
+
<svg class="pointer-events-none absolute top-3.5 left-4 h-5 w-5 text-fg-soft" viewBox="0 0 20 20" fill="currentColor">
|
|
66
66
|
<path fill-rule="evenodd" d="M8 4a4 4 0 100 8 4 4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 012 8z" clip-rule="evenodd" />
|
|
67
67
|
</svg>
|
|
68
68
|
<input
|
|
69
69
|
type="text"
|
|
70
|
-
class="h-12 w-full border-0 bg-transparent pl-11 pr-4 text-fg placeholder-
|
|
70
|
+
class="h-12 w-full border-0 bg-transparent pl-11 pr-4 text-fg placeholder-fg-soft focus:ring-0 sm:text-sm"
|
|
71
71
|
placeholder="Search..."
|
|
72
72
|
:value="query()"
|
|
73
73
|
@input="onQueryInput($event)"
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script server>
|
|
2
2
|
export const className = $props.className || ''
|
|
3
3
|
export const value = $props.value
|
|
4
|
+
export const valueJson = JSON.stringify(value === undefined ? null : value)
|
|
4
5
|
|
|
5
6
|
const baseClasses = 'flex cursor-pointer select-none items-center px-4 py-2 text-fg hover:bg-accent-solid hover:text-accent-ink'
|
|
6
7
|
export const itemClasses = `${baseClasses} ${className}`.trim()
|
|
@@ -8,7 +9,19 @@ export const itemClasses = `${baseClasses} ${className}`.trim()
|
|
|
8
9
|
|
|
9
10
|
<script client>
|
|
10
11
|
const emit = defineEmits()
|
|
11
|
-
|
|
12
|
+
/*
|
|
13
|
+
* JSON built on the server and emitted raw, rather than a 'null' sentinel
|
|
14
|
+
* through an ordinary interpolation.
|
|
15
|
+
*
|
|
16
|
+
* A `value === undefined ? 'null' : value` ternary was meant to put the bare
|
|
17
|
+
* token null into the script. An interpolation QUOTES a string, so what it
|
|
18
|
+
* emitted was the four-character string "null" -- truthy, in the one place a
|
|
19
|
+
* value is meant to be absent. JSON.stringify produces the correct literal for
|
|
20
|
+
* every type, null included, and raw interpolation passes it through unquoted.
|
|
21
|
+
* Calendar and DateRangePicker already avoid this sentinel and say why
|
|
22
|
+
* (stacksjs/stx#1981).
|
|
23
|
+
*/
|
|
24
|
+
const itemValue = {!! valueJson !!}
|
|
12
25
|
|
|
13
26
|
function onClick(event) {
|
|
14
27
|
emit('click', event)
|
package/src/ui/drawer/Drawer.stx
CHANGED
|
@@ -301,7 +301,7 @@ defineExpose({
|
|
|
301
301
|
<div class="{{ closeButtonClasses }}">
|
|
302
302
|
<button
|
|
303
303
|
type="button"
|
|
304
|
-
class="relative rounded-control text-neutral-300
|
|
304
|
+
class="relative rounded-control text-neutral-300 hover:text-white focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-accent"
|
|
305
305
|
@click="close()"
|
|
306
306
|
>
|
|
307
307
|
<span class="absolute -inset-2.5"></span>
|
|
@@ -14,21 +14,41 @@ const isOpen = state(false)
|
|
|
14
14
|
let rootEl = null
|
|
15
15
|
let outsideHandler = null
|
|
16
16
|
|
|
17
|
+
/*
|
|
18
|
+
* The trigger carries the open state for assistive tech. `isOpen` already
|
|
19
|
+
* drove `data-state` on the root, which styles the panel but says nothing to a
|
|
20
|
+
* screen reader: the button announced itself as a plain button, with no
|
|
21
|
+
* indication that it opens anything or whether it is open right now.
|
|
22
|
+
*/
|
|
23
|
+
function syncExpanded() {
|
|
24
|
+
if (!rootEl) return
|
|
25
|
+
const trigger = rootEl.querySelector('[data-stx-dropdown-button]')
|
|
26
|
+
if (!trigger) return
|
|
27
|
+
trigger.setAttribute('aria-expanded', isOpen() ? 'true' : 'false')
|
|
28
|
+
const panel = rootEl.querySelector('[data-stx-dropdown-items]')
|
|
29
|
+
if (!panel) return
|
|
30
|
+
if (!panel.id) panel.id = 'stx-dropdown-panel-' + dropdownInstanceId
|
|
31
|
+
trigger.setAttribute('aria-controls', panel.id)
|
|
32
|
+
}
|
|
33
|
+
|
|
17
34
|
function toggle() {
|
|
18
35
|
isOpen.set(!isOpen())
|
|
19
36
|
emit('change', isOpen())
|
|
37
|
+
syncExpanded()
|
|
20
38
|
}
|
|
21
39
|
|
|
22
40
|
function open() {
|
|
23
41
|
if (isOpen()) return
|
|
24
42
|
isOpen.set(true)
|
|
25
43
|
emit('change', true)
|
|
44
|
+
syncExpanded()
|
|
26
45
|
}
|
|
27
46
|
|
|
28
47
|
function close() {
|
|
29
48
|
if (!isOpen()) return
|
|
30
49
|
isOpen.set(false)
|
|
31
50
|
emit('change', false)
|
|
51
|
+
syncExpanded()
|
|
32
52
|
}
|
|
33
53
|
|
|
34
54
|
function onItemSelect(event) {
|
|
@@ -41,17 +61,119 @@ function onToggle(event) { event.stopPropagation(); toggle() }
|
|
|
41
61
|
function onOpen(event) { event.stopPropagation(); open() }
|
|
42
62
|
function onClose(event) { event.stopPropagation(); close() }
|
|
43
63
|
|
|
64
|
+
/*
|
|
65
|
+
* Escape dismisses it, from anywhere rather than only from inside the panel.
|
|
66
|
+
*
|
|
67
|
+
* Opening one of these does not move focus, so a keydown bound on the panel
|
|
68
|
+
* never sees the first Escape - focus is still on whatever opened it. Drawer
|
|
69
|
+
* reached the same conclusion and binds on the document; this follows it, and
|
|
70
|
+
* only acts while open so one open popup does not swallow Escape for the page.
|
|
71
|
+
*
|
|
72
|
+
* Focus goes back to the trigger, but only if it had moved into the panel:
|
|
73
|
+
* otherwise this would steal it from wherever the user actually is.
|
|
74
|
+
*/
|
|
75
|
+
function onDocumentKey(event) {
|
|
76
|
+
if (event.key !== 'Escape' || !isOpen()) return
|
|
77
|
+
close()
|
|
78
|
+
if (!rootEl) return
|
|
79
|
+
const active = rootEl.ownerDocument && rootEl.ownerDocument.activeElement
|
|
80
|
+
if (!active || !rootEl.contains(active)) return
|
|
81
|
+
const trigger = rootEl.querySelector('[data-stx-dropdown-button]')
|
|
82
|
+
if (trigger && trigger.focus) trigger.focus()
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/*
|
|
86
|
+
* Roving focus over the menu items.
|
|
87
|
+
*
|
|
88
|
+
* `role="menuitem"` on a div is not focusable on its own, so the items carry
|
|
89
|
+
* tabindex="-1" and focus is moved programmatically -- the APG menu-button
|
|
90
|
+
* arrangement. Only the items are in the ring; a disabled one is skipped
|
|
91
|
+
* rather than focused and ignored, because landing on something inert reads as
|
|
92
|
+
* the menu being broken.
|
|
93
|
+
*/
|
|
94
|
+
function menuItems() {
|
|
95
|
+
if (!rootEl) return []
|
|
96
|
+
const all = rootEl.querySelectorAll('[data-stx-dropdown-item]')
|
|
97
|
+
return Array.prototype.filter.call(all, item => item.getAttribute('aria-disabled') !== 'true')
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function focusItemAt(index) {
|
|
101
|
+
const items = menuItems()
|
|
102
|
+
if (!items.length) return
|
|
103
|
+
const target = items[(index + items.length) % items.length]
|
|
104
|
+
if (target && target.focus) target.focus()
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function focusedItemIndex() {
|
|
108
|
+
const doc = rootEl && rootEl.ownerDocument
|
|
109
|
+
return doc ? menuItems().indexOf(doc.activeElement) : -1
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/*
|
|
113
|
+
* Keys are handled only while the event comes from inside this dropdown.
|
|
114
|
+
* Bound on the document so Escape works before focus has moved into the panel,
|
|
115
|
+
* which means an unguarded ArrowDown here would hijack scrolling for the whole
|
|
116
|
+
* page.
|
|
117
|
+
*/
|
|
118
|
+
function onMenuKey(event) {
|
|
119
|
+
if (!rootEl || !rootEl.contains(event.target)) return
|
|
120
|
+
const key = event.key
|
|
121
|
+
|
|
122
|
+
if (!isOpen()) {
|
|
123
|
+
// ArrowDown opens and lands on the first item; ArrowUp on the last, which
|
|
124
|
+
// is how a menu button reached from below behaves.
|
|
125
|
+
if (key !== 'ArrowDown' && key !== 'ArrowUp') return
|
|
126
|
+
event.preventDefault()
|
|
127
|
+
open()
|
|
128
|
+
focusItemAt(key === 'ArrowDown' ? 0 : menuItems().length - 1)
|
|
129
|
+
return
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (key === 'ArrowDown' || key === 'ArrowUp') {
|
|
133
|
+
event.preventDefault()
|
|
134
|
+
const current = focusedItemIndex()
|
|
135
|
+
if (current === -1) focusItemAt(key === 'ArrowDown' ? 0 : menuItems().length - 1)
|
|
136
|
+
else focusItemAt(current + (key === 'ArrowDown' ? 1 : -1))
|
|
137
|
+
return
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (key === 'Home' || key === 'End') {
|
|
141
|
+
event.preventDefault()
|
|
142
|
+
focusItemAt(key === 'Home' ? 0 : menuItems().length - 1)
|
|
143
|
+
return
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (key === 'Enter' || key === ' ') {
|
|
147
|
+
// The item is a div, so Enter does not activate it the way it would a
|
|
148
|
+
// button. Clicking it runs the handler the item already has.
|
|
149
|
+
const current = focusedItemIndex()
|
|
150
|
+
if (current === -1) return
|
|
151
|
+
event.preventDefault()
|
|
152
|
+
menuItems()[current].click()
|
|
153
|
+
return
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Tabbing out of an open menu closes it, rather than leaving it hanging
|
|
157
|
+
// over the content the user has moved to.
|
|
158
|
+
if (key === 'Tab') close()
|
|
159
|
+
}
|
|
160
|
+
|
|
44
161
|
onMount(() => {
|
|
45
162
|
rootEl = document.querySelector(`[data-dropdown-id="${dropdownInstanceId}"]`)
|
|
163
|
+
syncExpanded()
|
|
46
164
|
outsideHandler = (event) => {
|
|
47
165
|
if (!isOpen()) return
|
|
48
166
|
if (rootEl && !rootEl.contains(event.target)) close()
|
|
49
167
|
}
|
|
50
168
|
document.addEventListener('click', outsideHandler, true)
|
|
169
|
+
document.addEventListener('keydown', onDocumentKey)
|
|
170
|
+
document.addEventListener('keydown', onMenuKey)
|
|
51
171
|
})
|
|
52
172
|
|
|
53
173
|
onDestroy(() => {
|
|
54
174
|
if (outsideHandler) document.removeEventListener('click', outsideHandler, true)
|
|
175
|
+
document.removeEventListener('keydown', onDocumentKey)
|
|
176
|
+
document.removeEventListener('keydown', onMenuKey)
|
|
55
177
|
})
|
|
56
178
|
|
|
57
179
|
const dataState = derived(() => isOpen() ? 'open' : 'closed')
|