git ssb

16+

Dominic / patchbay



Commit 9946a76c936405d3e8fa3bfe58b7892adb8c631f

change modal to auto-focus on first input/textarea, add Esc to close listener

mixmix committed on 11/6/2018, 9:04:30 PM
Parent: 3f492d0842220c7734124da1dbd5752a49994324

Files changed

app/html/modal.jschanged
package-lock.jsonchanged
app/html/modal.jsView
@@ -6,19 +6,44 @@
66 exports.create = (api) => {
77 return nest('app.html.modal', (content, { isOpen, onClose, className = '' } = {}) => {
88 if (typeof isOpen !== 'function') isOpen = Value(false)
99
10- const openMe = () => isOpen.set(true)
10 + const openMe = () => {
11 + isOpen.set(true)
12 + }
1113 const closeMe = () => {
1214 isOpen.set(false)
1315 if (typeof onClose === 'function') onClose()
1416 }
1517
16- const lb = h('Modal', { classList: [when(isOpen, '-open', '-close'), className], 'ev-click': closeMe },
17- h('div.content', {'ev-click': (ev) => ev.stopPropagation()}, [
18- content
19- ]))
18 + const lb = h('Modal',
19 + {
20 + classList: [ className, when(isOpen, '-open', '-close') ],
21 + 'ev-click': closeMe,
22 + 'ev-keydown': ev => {
23 + if (ev.keyCode === 27) closeMe() // Escape
24 + }
25 + },
26 + [
27 + h('div.content', { 'ev-click': (ev) => ev.stopPropagation() }, [
28 + content
29 + ])
30 + ]
31 + )
2032
33 + isOpen(state => {
34 + if (!state) return
35 +
36 + focus()
37 + function focus () {
38 + if (!lb.isConnected) setTimeout(focus, 200)
39 + else {
40 + const target = lb.querySelector('input') || lb.querySelector('textarea')
41 + if (target) target.focus()
42 + }
43 + }
44 + })
45 +
2146 lb.open = openMe
2247 lb.close = closeMe
2348
2449 return lb
package-lock.jsonView
The diff is too large to show. Use a local git client to view these changes.
Old file size: 374391 bytes
New file size: 374372 bytes

Built with git-ssb-web