@pyreon/elements 0.11.5 → 0.11.7
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/README.md +38 -35
- package/lib/index.d.ts +15 -15
- package/package.json +24 -24
- package/src/Element/component.tsx +14 -14
- package/src/Element/constants.ts +25 -25
- package/src/Element/index.ts +2 -2
- package/src/Element/types.ts +3 -3
- package/src/Element/utils.ts +1 -1
- package/src/List/component.tsx +7 -7
- package/src/List/index.ts +2 -2
- package/src/Overlay/component.tsx +22 -22
- package/src/Overlay/context.tsx +2 -2
- package/src/Overlay/index.ts +3 -3
- package/src/Overlay/useOverlay.tsx +97 -97
- package/src/Portal/component.tsx +6 -6
- package/src/Portal/index.ts +2 -2
- package/src/Text/component.tsx +6 -6
- package/src/Text/index.ts +2 -2
- package/src/Text/styled.ts +4 -4
- package/src/Util/component.tsx +5 -5
- package/src/Util/index.ts +2 -2
- package/src/__tests__/Content.test.tsx +46 -46
- package/src/__tests__/Element.test.ts +251 -251
- package/src/__tests__/Iterator.test.ts +142 -142
- package/src/__tests__/List.test.ts +61 -61
- package/src/__tests__/Overlay.test.ts +125 -125
- package/src/__tests__/Portal.test.ts +33 -33
- package/src/__tests__/Text.test.ts +128 -128
- package/src/__tests__/Util.test.ts +31 -31
- package/src/__tests__/Wrapper.test.tsx +60 -60
- package/src/__tests__/equalBeforeAfter.test.ts +41 -41
- package/src/__tests__/helpers.test.ts +29 -29
- package/src/__tests__/overlayContext.test.tsx +14 -14
- package/src/__tests__/responsiveProps.test.ts +116 -116
- package/src/__tests__/useOverlay.test.ts +283 -283
- package/src/__tests__/utils.test.ts +43 -43
- package/src/constants.ts +1 -1
- package/src/helpers/Content/component.tsx +5 -5
- package/src/helpers/Content/index.ts +1 -1
- package/src/helpers/Content/styled.ts +16 -16
- package/src/helpers/Content/types.ts +7 -7
- package/src/helpers/Iterator/component.tsx +28 -28
- package/src/helpers/Iterator/index.ts +2 -2
- package/src/helpers/Iterator/types.ts +3 -3
- package/src/helpers/Wrapper/component.tsx +6 -6
- package/src/helpers/Wrapper/index.ts +1 -1
- package/src/helpers/Wrapper/styled.ts +8 -8
- package/src/helpers/Wrapper/types.ts +3 -3
- package/src/helpers/Wrapper/utils.ts +1 -1
- package/src/helpers/index.ts +2 -2
- package/src/index.ts +16 -16
- package/src/types.ts +7 -7
- package/src/utils.ts +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ComponentFn, VNode, VNodeChild } from
|
|
2
|
-
import { describe, expect, it, vi } from
|
|
1
|
+
import type { ComponentFn, VNode, VNodeChild } from '@pyreon/core'
|
|
2
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
3
3
|
|
|
4
4
|
// ---------------------------------------------------------------------------
|
|
5
5
|
// Mocks — signal() in @pyreon/reactivity returns a Signal object (callable
|
|
@@ -7,7 +7,7 @@ import { describe, expect, it, vi } from "vitest"
|
|
|
7
7
|
// [getter, setter]. We mock signal() to return a simple tuple.
|
|
8
8
|
// ---------------------------------------------------------------------------
|
|
9
9
|
|
|
10
|
-
vi.mock(
|
|
10
|
+
vi.mock('@pyreon/reactivity', () => {
|
|
11
11
|
const signal = <T>(initial: T) => {
|
|
12
12
|
let value = initial
|
|
13
13
|
const s = (() => value) as (() => T) & {
|
|
@@ -41,7 +41,7 @@ vi.mock("@pyreon/reactivity", () => {
|
|
|
41
41
|
})
|
|
42
42
|
|
|
43
43
|
// onMount / onUnmount are no-ops outside a renderer
|
|
44
|
-
vi.mock(
|
|
44
|
+
vi.mock('@pyreon/core', async (importOriginal) => {
|
|
45
45
|
const actual = (await importOriginal()) as Record<string, unknown>
|
|
46
46
|
return {
|
|
47
47
|
...actual,
|
|
@@ -52,20 +52,20 @@ vi.mock("@pyreon/core", async (importOriginal) => {
|
|
|
52
52
|
})
|
|
53
53
|
|
|
54
54
|
// render + throttle from @pyreon/ui-core
|
|
55
|
-
vi.mock(
|
|
56
|
-
const { h: createElement } = await import(
|
|
55
|
+
vi.mock('@pyreon/ui-core', async () => {
|
|
56
|
+
const { h: createElement } = await import('@pyreon/core')
|
|
57
57
|
|
|
58
58
|
const render = (content: unknown, attachProps?: Record<string, unknown>) => {
|
|
59
59
|
if (!content) return null
|
|
60
60
|
const t = typeof content
|
|
61
|
-
if (t ===
|
|
61
|
+
if (t === 'string' || t === 'number' || t === 'boolean' || t === 'bigint') {
|
|
62
62
|
return content as VNodeChild
|
|
63
63
|
}
|
|
64
64
|
if (Array.isArray(content)) return content as VNodeChild
|
|
65
|
-
if (typeof content ===
|
|
65
|
+
if (typeof content === 'function') {
|
|
66
66
|
return createElement(content as ComponentFn, (attachProps ?? {}) as any)
|
|
67
67
|
}
|
|
68
|
-
if (typeof content ===
|
|
68
|
+
if (typeof content === 'object') {
|
|
69
69
|
return content as VNodeChild
|
|
70
70
|
}
|
|
71
71
|
return content as VNodeChild
|
|
@@ -83,57 +83,57 @@ vi.mock("@pyreon/ui-core", async () => {
|
|
|
83
83
|
})
|
|
84
84
|
|
|
85
85
|
// @pyreon/unistyle — value() used in assignContentPosition
|
|
86
|
-
vi.mock(
|
|
87
|
-
value: (v: unknown) => (typeof v ===
|
|
86
|
+
vi.mock('@pyreon/unistyle', () => ({
|
|
87
|
+
value: (v: unknown) => (typeof v === 'number' ? `${v}px` : v),
|
|
88
88
|
}))
|
|
89
89
|
|
|
90
|
-
import { Fragment, h } from
|
|
91
|
-
import { Overlay, useOverlay } from
|
|
90
|
+
import { Fragment, h } from '@pyreon/core'
|
|
91
|
+
import { Overlay, useOverlay } from '../Overlay'
|
|
92
92
|
|
|
93
93
|
const asVNode = (v: unknown) => v as VNode
|
|
94
94
|
|
|
95
95
|
// ---------------------------------------------------------------------------
|
|
96
96
|
// useOverlay
|
|
97
97
|
// ---------------------------------------------------------------------------
|
|
98
|
-
describe(
|
|
99
|
-
describe(
|
|
100
|
-
it(
|
|
98
|
+
describe('useOverlay', () => {
|
|
99
|
+
describe('active state', () => {
|
|
100
|
+
it('starts inactive by default', () => {
|
|
101
101
|
const overlay = useOverlay()
|
|
102
102
|
expect(overlay.active()).toBe(false)
|
|
103
103
|
})
|
|
104
104
|
|
|
105
|
-
it(
|
|
105
|
+
it('starts active when isOpen is true', () => {
|
|
106
106
|
const overlay = useOverlay({ isOpen: true })
|
|
107
107
|
expect(overlay.active()).toBe(true)
|
|
108
108
|
})
|
|
109
109
|
|
|
110
|
-
it(
|
|
110
|
+
it('showContent sets active to true', () => {
|
|
111
111
|
const overlay = useOverlay()
|
|
112
112
|
overlay.showContent()
|
|
113
113
|
expect(overlay.active()).toBe(true)
|
|
114
114
|
})
|
|
115
115
|
|
|
116
|
-
it(
|
|
116
|
+
it('hideContent sets active to false', () => {
|
|
117
117
|
const overlay = useOverlay({ isOpen: true })
|
|
118
118
|
overlay.hideContent()
|
|
119
119
|
expect(overlay.active()).toBe(false)
|
|
120
120
|
})
|
|
121
121
|
|
|
122
|
-
it(
|
|
122
|
+
it('showContent is idempotent', () => {
|
|
123
123
|
const overlay = useOverlay()
|
|
124
124
|
overlay.showContent()
|
|
125
125
|
overlay.showContent()
|
|
126
126
|
expect(overlay.active()).toBe(true)
|
|
127
127
|
})
|
|
128
128
|
|
|
129
|
-
it(
|
|
129
|
+
it('hideContent is idempotent', () => {
|
|
130
130
|
const overlay = useOverlay()
|
|
131
131
|
overlay.hideContent()
|
|
132
132
|
overlay.hideContent()
|
|
133
133
|
expect(overlay.active()).toBe(false)
|
|
134
134
|
})
|
|
135
135
|
|
|
136
|
-
it(
|
|
136
|
+
it('toggle between show/hide works', () => {
|
|
137
137
|
const overlay = useOverlay()
|
|
138
138
|
overlay.showContent()
|
|
139
139
|
expect(overlay.active()).toBe(true)
|
|
@@ -144,8 +144,8 @@ describe("useOverlay", () => {
|
|
|
144
144
|
})
|
|
145
145
|
})
|
|
146
146
|
|
|
147
|
-
describe(
|
|
148
|
-
it(
|
|
147
|
+
describe('callbacks', () => {
|
|
148
|
+
it('calls onOpen when showing content', () => {
|
|
149
149
|
let opened = false
|
|
150
150
|
const overlay = useOverlay({
|
|
151
151
|
onOpen: () => {
|
|
@@ -156,7 +156,7 @@ describe("useOverlay", () => {
|
|
|
156
156
|
expect(opened).toBe(true)
|
|
157
157
|
})
|
|
158
158
|
|
|
159
|
-
it(
|
|
159
|
+
it('calls onClose when hiding content', () => {
|
|
160
160
|
let closed = false
|
|
161
161
|
const overlay = useOverlay({
|
|
162
162
|
isOpen: true,
|
|
@@ -169,60 +169,60 @@ describe("useOverlay", () => {
|
|
|
169
169
|
})
|
|
170
170
|
})
|
|
171
171
|
|
|
172
|
-
describe(
|
|
173
|
-
it(
|
|
174
|
-
const overlay = useOverlay({ alignX:
|
|
175
|
-
expect(overlay.alignX()).toBe(
|
|
172
|
+
describe('alignment signals', () => {
|
|
173
|
+
it('exposes alignX signal with default', () => {
|
|
174
|
+
const overlay = useOverlay({ alignX: 'center' })
|
|
175
|
+
expect(overlay.alignX()).toBe('center')
|
|
176
176
|
})
|
|
177
177
|
|
|
178
|
-
it(
|
|
179
|
-
const overlay = useOverlay({ alignY:
|
|
180
|
-
expect(overlay.alignY()).toBe(
|
|
178
|
+
it('exposes alignY signal with default', () => {
|
|
179
|
+
const overlay = useOverlay({ alignY: 'top' })
|
|
180
|
+
expect(overlay.alignY()).toBe('top')
|
|
181
181
|
})
|
|
182
182
|
|
|
183
|
-
it(
|
|
183
|
+
it('defaults alignX to left', () => {
|
|
184
184
|
const overlay = useOverlay()
|
|
185
|
-
expect(overlay.alignX()).toBe(
|
|
185
|
+
expect(overlay.alignX()).toBe('left')
|
|
186
186
|
})
|
|
187
187
|
|
|
188
|
-
it(
|
|
188
|
+
it('defaults alignY to bottom', () => {
|
|
189
189
|
const overlay = useOverlay()
|
|
190
|
-
expect(overlay.alignY()).toBe(
|
|
190
|
+
expect(overlay.alignY()).toBe('bottom')
|
|
191
191
|
})
|
|
192
192
|
})
|
|
193
193
|
|
|
194
|
-
describe(
|
|
195
|
-
it(
|
|
194
|
+
describe('ref callbacks', () => {
|
|
195
|
+
it('provides triggerRef callback', () => {
|
|
196
196
|
const overlay = useOverlay()
|
|
197
|
-
expect(typeof overlay.triggerRef).toBe(
|
|
197
|
+
expect(typeof overlay.triggerRef).toBe('function')
|
|
198
198
|
})
|
|
199
199
|
|
|
200
|
-
it(
|
|
200
|
+
it('provides contentRef callback', () => {
|
|
201
201
|
const overlay = useOverlay()
|
|
202
|
-
expect(typeof overlay.contentRef).toBe(
|
|
202
|
+
expect(typeof overlay.contentRef).toBe('function')
|
|
203
203
|
})
|
|
204
204
|
})
|
|
205
205
|
|
|
206
|
-
describe(
|
|
207
|
-
it(
|
|
206
|
+
describe('blocked state', () => {
|
|
207
|
+
it('starts unblocked', () => {
|
|
208
208
|
const overlay = useOverlay()
|
|
209
209
|
expect(overlay.blocked()).toBe(false)
|
|
210
210
|
})
|
|
211
211
|
|
|
212
|
-
it(
|
|
212
|
+
it('setBlocked increments blocked count', () => {
|
|
213
213
|
const overlay = useOverlay()
|
|
214
214
|
overlay.setBlocked()
|
|
215
215
|
expect(overlay.blocked()).toBe(true)
|
|
216
216
|
})
|
|
217
217
|
|
|
218
|
-
it(
|
|
218
|
+
it('setUnblocked decrements blocked count', () => {
|
|
219
219
|
const overlay = useOverlay()
|
|
220
220
|
overlay.setBlocked()
|
|
221
221
|
overlay.setUnblocked()
|
|
222
222
|
expect(overlay.blocked()).toBe(false)
|
|
223
223
|
})
|
|
224
224
|
|
|
225
|
-
it(
|
|
225
|
+
it('multiple setBlocked calls require equal setUnblocked calls', () => {
|
|
226
226
|
const overlay = useOverlay()
|
|
227
227
|
overlay.setBlocked()
|
|
228
228
|
overlay.setBlocked()
|
|
@@ -232,7 +232,7 @@ describe("useOverlay", () => {
|
|
|
232
232
|
expect(overlay.blocked()).toBe(false)
|
|
233
233
|
})
|
|
234
234
|
|
|
235
|
-
it(
|
|
235
|
+
it('setUnblocked does not go below zero', () => {
|
|
236
236
|
const overlay = useOverlay()
|
|
237
237
|
overlay.setUnblocked()
|
|
238
238
|
overlay.setUnblocked()
|
|
@@ -240,24 +240,24 @@ describe("useOverlay", () => {
|
|
|
240
240
|
})
|
|
241
241
|
})
|
|
242
242
|
|
|
243
|
-
describe(
|
|
244
|
-
it(
|
|
243
|
+
describe('setupListeners', () => {
|
|
244
|
+
it('returns a cleanup function', () => {
|
|
245
245
|
const overlay = useOverlay()
|
|
246
246
|
const cleanup = overlay.setupListeners()
|
|
247
|
-
expect(typeof cleanup).toBe(
|
|
247
|
+
expect(typeof cleanup).toBe('function')
|
|
248
248
|
cleanup()
|
|
249
249
|
})
|
|
250
250
|
})
|
|
251
251
|
|
|
252
|
-
describe(
|
|
253
|
-
it(
|
|
252
|
+
describe('disabled state', () => {
|
|
253
|
+
it('forces active to false when disabled', () => {
|
|
254
254
|
const overlay = useOverlay({ isOpen: true, disabled: true })
|
|
255
255
|
expect(overlay.active()).toBe(false)
|
|
256
256
|
})
|
|
257
257
|
})
|
|
258
258
|
|
|
259
|
-
describe(
|
|
260
|
-
it(
|
|
259
|
+
describe('each hook instance has independent state', () => {
|
|
260
|
+
it('two useOverlay instances do not share state', () => {
|
|
261
261
|
const overlay1 = useOverlay()
|
|
262
262
|
const overlay2 = useOverlay()
|
|
263
263
|
|
|
@@ -275,22 +275,22 @@ describe("useOverlay", () => {
|
|
|
275
275
|
})
|
|
276
276
|
})
|
|
277
277
|
|
|
278
|
-
describe(
|
|
279
|
-
it(
|
|
278
|
+
describe('Provider', () => {
|
|
279
|
+
it('exposes Provider component', () => {
|
|
280
280
|
const overlay = useOverlay()
|
|
281
|
-
expect(typeof overlay.Provider).toBe(
|
|
281
|
+
expect(typeof overlay.Provider).toBe('function')
|
|
282
282
|
})
|
|
283
283
|
})
|
|
284
284
|
|
|
285
|
-
describe(
|
|
286
|
-
it(
|
|
287
|
-
const overlay = useOverlay({ align:
|
|
288
|
-
expect(overlay.align).toBe(
|
|
285
|
+
describe('static align property', () => {
|
|
286
|
+
it('returns align value passed in props', () => {
|
|
287
|
+
const overlay = useOverlay({ align: 'top' })
|
|
288
|
+
expect(overlay.align).toBe('top')
|
|
289
289
|
})
|
|
290
290
|
|
|
291
|
-
it(
|
|
291
|
+
it('defaults align to bottom', () => {
|
|
292
292
|
const overlay = useOverlay()
|
|
293
|
-
expect(overlay.align).toBe(
|
|
293
|
+
expect(overlay.align).toBe('bottom')
|
|
294
294
|
})
|
|
295
295
|
})
|
|
296
296
|
})
|
|
@@ -298,45 +298,45 @@ describe("useOverlay", () => {
|
|
|
298
298
|
// ---------------------------------------------------------------------------
|
|
299
299
|
// Overlay component
|
|
300
300
|
// ---------------------------------------------------------------------------
|
|
301
|
-
describe(
|
|
302
|
-
describe(
|
|
303
|
-
it(
|
|
301
|
+
describe('Overlay component', () => {
|
|
302
|
+
describe('VNode structure', () => {
|
|
303
|
+
it('returns a Fragment', () => {
|
|
304
304
|
const result = asVNode(
|
|
305
305
|
Overlay({
|
|
306
|
-
trigger: h(
|
|
307
|
-
children: h(
|
|
306
|
+
trigger: h('button', null, 'Click'),
|
|
307
|
+
children: h('div', null, 'Panel'),
|
|
308
308
|
}),
|
|
309
309
|
)
|
|
310
310
|
expect(result.type).toBe(Fragment)
|
|
311
311
|
})
|
|
312
312
|
|
|
313
|
-
it(
|
|
313
|
+
it('has trigger as first child and reactive function as second child', () => {
|
|
314
314
|
const result = asVNode(
|
|
315
315
|
Overlay({
|
|
316
|
-
trigger: h(
|
|
317
|
-
children: h(
|
|
316
|
+
trigger: h('button', null, 'Click'),
|
|
317
|
+
children: h('div', null, 'Panel'),
|
|
318
318
|
}),
|
|
319
319
|
)
|
|
320
320
|
expect(result.children.length).toBe(2)
|
|
321
|
-
expect(typeof result.children[1]).toBe(
|
|
321
|
+
expect(typeof result.children[1]).toBe('function')
|
|
322
322
|
})
|
|
323
323
|
|
|
324
|
-
it(
|
|
324
|
+
it('content function returns null when closed', () => {
|
|
325
325
|
const result = asVNode(
|
|
326
326
|
Overlay({
|
|
327
|
-
trigger: h(
|
|
328
|
-
children: h(
|
|
327
|
+
trigger: h('button', null, 'Click'),
|
|
328
|
+
children: h('div', null, 'Panel'),
|
|
329
329
|
}),
|
|
330
330
|
)
|
|
331
331
|
const contentFn = result.children[1] as () => VNodeChild
|
|
332
332
|
expect(contentFn()).toBeNull()
|
|
333
333
|
})
|
|
334
334
|
|
|
335
|
-
it(
|
|
335
|
+
it('content function returns Portal VNode when opened via isOpen', () => {
|
|
336
336
|
const result = asVNode(
|
|
337
337
|
Overlay({
|
|
338
|
-
trigger: h(
|
|
339
|
-
children: h(
|
|
338
|
+
trigger: h('button', null, 'Click'),
|
|
339
|
+
children: h('div', null, 'Panel'),
|
|
340
340
|
isOpen: true,
|
|
341
341
|
}),
|
|
342
342
|
)
|
|
@@ -346,107 +346,107 @@ describe("Overlay component", () => {
|
|
|
346
346
|
})
|
|
347
347
|
})
|
|
348
348
|
|
|
349
|
-
describe(
|
|
350
|
-
it(
|
|
349
|
+
describe('trigger rendered via ComponentFn receives overlay props', () => {
|
|
350
|
+
it('passes active and aria props to trigger component', () => {
|
|
351
351
|
const TriggerComp: ComponentFn = (props: any) =>
|
|
352
|
-
h(
|
|
352
|
+
h('button', null, props.active ? 'Open' : 'Closed')
|
|
353
353
|
|
|
354
354
|
const result = asVNode(
|
|
355
355
|
Overlay({
|
|
356
356
|
trigger: TriggerComp,
|
|
357
|
-
children: h(
|
|
357
|
+
children: h('div', null, 'Panel'),
|
|
358
358
|
}),
|
|
359
359
|
)
|
|
360
360
|
const triggerVNode = asVNode(result.children[0])
|
|
361
361
|
expect(triggerVNode.type).toBe(TriggerComp)
|
|
362
362
|
expect(triggerVNode.props.active).toBe(false)
|
|
363
|
-
expect(triggerVNode.props[
|
|
364
|
-
expect(triggerVNode.props[
|
|
363
|
+
expect(triggerVNode.props['aria-expanded']).toBe(false)
|
|
364
|
+
expect(triggerVNode.props['aria-haspopup']).toBe('menu')
|
|
365
365
|
})
|
|
366
366
|
|
|
367
|
-
it(
|
|
368
|
-
const TriggerComp: ComponentFn = (_props: any) => h(
|
|
367
|
+
it('passes active=true when isOpen is true', () => {
|
|
368
|
+
const TriggerComp: ComponentFn = (_props: any) => h('button', null, 'T')
|
|
369
369
|
|
|
370
370
|
const result = asVNode(
|
|
371
371
|
Overlay({
|
|
372
372
|
trigger: TriggerComp,
|
|
373
|
-
children: h(
|
|
373
|
+
children: h('div', null, 'Panel'),
|
|
374
374
|
isOpen: true,
|
|
375
375
|
}),
|
|
376
376
|
)
|
|
377
377
|
const triggerVNode = asVNode(result.children[0])
|
|
378
378
|
expect(triggerVNode.props.active).toBe(true)
|
|
379
|
-
expect(triggerVNode.props[
|
|
379
|
+
expect(triggerVNode.props['aria-expanded']).toBe(true)
|
|
380
380
|
})
|
|
381
381
|
|
|
382
|
-
it(
|
|
383
|
-
const TriggerComp: ComponentFn = (_props: any) => h(
|
|
382
|
+
it('passes aria-haspopup=dialog for modal type', () => {
|
|
383
|
+
const TriggerComp: ComponentFn = (_props: any) => h('button', null, 'T')
|
|
384
384
|
|
|
385
385
|
const result = asVNode(
|
|
386
386
|
Overlay({
|
|
387
387
|
trigger: TriggerComp,
|
|
388
|
-
children: h(
|
|
389
|
-
type:
|
|
388
|
+
children: h('div', null, 'Panel'),
|
|
389
|
+
type: 'modal',
|
|
390
390
|
}),
|
|
391
391
|
)
|
|
392
392
|
const triggerVNode = asVNode(result.children[0])
|
|
393
|
-
expect(triggerVNode.props[
|
|
393
|
+
expect(triggerVNode.props['aria-haspopup']).toBe('dialog')
|
|
394
394
|
})
|
|
395
395
|
|
|
396
|
-
it(
|
|
397
|
-
const TriggerComp: ComponentFn = (_props: any) => h(
|
|
396
|
+
it('passes aria-haspopup=true for tooltip type', () => {
|
|
397
|
+
const TriggerComp: ComponentFn = (_props: any) => h('button', null, 'T')
|
|
398
398
|
|
|
399
399
|
const result = asVNode(
|
|
400
400
|
Overlay({
|
|
401
401
|
trigger: TriggerComp,
|
|
402
|
-
children: h(
|
|
403
|
-
type:
|
|
402
|
+
children: h('div', null, 'Panel'),
|
|
403
|
+
type: 'tooltip',
|
|
404
404
|
}),
|
|
405
405
|
)
|
|
406
406
|
const triggerVNode = asVNode(result.children[0])
|
|
407
|
-
expect(triggerVNode.props[
|
|
407
|
+
expect(triggerVNode.props['aria-haspopup']).toBe('true')
|
|
408
408
|
})
|
|
409
409
|
|
|
410
|
-
it(
|
|
411
|
-
const TriggerComp: ComponentFn = (_props: any) => h(
|
|
410
|
+
it('passes ref via triggerRefName prop', () => {
|
|
411
|
+
const TriggerComp: ComponentFn = (_props: any) => h('button', null, 'T')
|
|
412
412
|
|
|
413
413
|
const result = asVNode(
|
|
414
414
|
Overlay({
|
|
415
415
|
trigger: TriggerComp,
|
|
416
|
-
children: h(
|
|
417
|
-
triggerRefName:
|
|
416
|
+
children: h('div', null, 'Panel'),
|
|
417
|
+
triggerRefName: 'innerRef',
|
|
418
418
|
}),
|
|
419
419
|
)
|
|
420
420
|
const triggerVNode = asVNode(result.children[0])
|
|
421
|
-
expect(typeof triggerVNode.props.innerRef).toBe(
|
|
421
|
+
expect(typeof triggerVNode.props.innerRef).toBe('function')
|
|
422
422
|
// default 'ref' should not be set
|
|
423
423
|
expect(triggerVNode.props.ref).toBeUndefined()
|
|
424
424
|
})
|
|
425
425
|
|
|
426
|
-
it(
|
|
427
|
-
const TriggerComp: ComponentFn = (_props: any) => h(
|
|
426
|
+
it('passes showContent/hideContent for manual openOn', () => {
|
|
427
|
+
const TriggerComp: ComponentFn = (_props: any) => h('button', null, 'T')
|
|
428
428
|
|
|
429
429
|
const result = asVNode(
|
|
430
430
|
Overlay({
|
|
431
431
|
trigger: TriggerComp,
|
|
432
|
-
children: h(
|
|
433
|
-
openOn:
|
|
432
|
+
children: h('div', null, 'Panel'),
|
|
433
|
+
openOn: 'manual',
|
|
434
434
|
}),
|
|
435
435
|
)
|
|
436
436
|
const triggerVNode = asVNode(result.children[0])
|
|
437
|
-
expect(typeof triggerVNode.props.showContent).toBe(
|
|
438
|
-
expect(typeof triggerVNode.props.hideContent).toBe(
|
|
437
|
+
expect(typeof triggerVNode.props.showContent).toBe('function')
|
|
438
|
+
expect(typeof triggerVNode.props.hideContent).toBe('function')
|
|
439
439
|
})
|
|
440
440
|
|
|
441
|
-
it(
|
|
442
|
-
const TriggerComp: ComponentFn = (_props: any) => h(
|
|
441
|
+
it('does not pass showContent/hideContent for click openOn', () => {
|
|
442
|
+
const TriggerComp: ComponentFn = (_props: any) => h('button', null, 'T')
|
|
443
443
|
|
|
444
444
|
const result = asVNode(
|
|
445
445
|
Overlay({
|
|
446
446
|
trigger: TriggerComp,
|
|
447
|
-
children: h(
|
|
448
|
-
openOn:
|
|
449
|
-
closeOn:
|
|
447
|
+
children: h('div', null, 'Panel'),
|
|
448
|
+
openOn: 'click',
|
|
449
|
+
closeOn: 'click',
|
|
450
450
|
}),
|
|
451
451
|
)
|
|
452
452
|
const triggerVNode = asVNode(result.children[0])
|
|
@@ -455,31 +455,31 @@ describe("Overlay component", () => {
|
|
|
455
455
|
})
|
|
456
456
|
})
|
|
457
457
|
|
|
458
|
-
describe(
|
|
459
|
-
it(
|
|
460
|
-
const trigger = h(
|
|
458
|
+
describe('trigger as VNode is passed through', () => {
|
|
459
|
+
it('returns trigger VNode as-is when not a function', () => {
|
|
460
|
+
const trigger = h('button', { id: 'btn' }, 'Click')
|
|
461
461
|
const result = asVNode(
|
|
462
462
|
Overlay({
|
|
463
463
|
trigger,
|
|
464
|
-
children: h(
|
|
464
|
+
children: h('div', null, 'Panel'),
|
|
465
465
|
}),
|
|
466
466
|
)
|
|
467
467
|
// render() passes VNode objects through directly
|
|
468
468
|
const triggerChild = asVNode(result.children[0])
|
|
469
|
-
expect(triggerChild.type).toBe(
|
|
470
|
-
expect(triggerChild.props.id).toBe(
|
|
469
|
+
expect(triggerChild.type).toBe('button')
|
|
470
|
+
expect(triggerChild.props.id).toBe('btn')
|
|
471
471
|
})
|
|
472
472
|
})
|
|
473
473
|
|
|
474
|
-
describe(
|
|
475
|
-
it(
|
|
474
|
+
describe('displayName and metadata', () => {
|
|
475
|
+
it('has displayName set', () => {
|
|
476
476
|
expect(Overlay.displayName).toBeDefined()
|
|
477
|
-
expect(Overlay.displayName).toContain(
|
|
477
|
+
expect(Overlay.displayName).toContain('Overlay')
|
|
478
478
|
})
|
|
479
479
|
|
|
480
|
-
it(
|
|
480
|
+
it('has PYREON__COMPONENT set', () => {
|
|
481
481
|
expect(Overlay.PYREON__COMPONENT).toBeDefined()
|
|
482
|
-
expect(Overlay.PYREON__COMPONENT).toContain(
|
|
482
|
+
expect(Overlay.PYREON__COMPONENT).toContain('Overlay')
|
|
483
483
|
})
|
|
484
484
|
})
|
|
485
485
|
})
|