|
| 1 | +<!-- |
| 2 | + PopoverBehaviorDemo — VR behavioral cell for @rozie-ui/popover (wraps |
| 3 | + @floating-ui/dom). Drives the click-trigger floating primitive: a two-way |
| 4 | + r-model:open (live open + @change readouts), the anchor-click open gesture, |
| 5 | + Escape + click-outside dismissal, and a `set-closed` direct-model-write button |
| 6 | + (programmatic CLOSE). The floating panel is r-if="open" so the spec asserts |
| 7 | + presence/absence via role="dialog". See popover.spec.ts. Behavioral-only. |
| 8 | + |
| 9 | + WHY THE DIRECT-MODEL-WRITE IS A *CLOSE*, NOT AN OPEN: a programmatic OPEN from |
| 10 | + an external button races with the click-outside dismissal on Svelte — the |
| 11 | + opening click keeps bubbling to `document`, where the just-attached outside |
| 12 | + listener (Svelte attaches it synchronously on the same tick; the other 5 targets |
| 13 | + defer it) sees the click target is outside the popover and immediately dismisses. |
| 14 | + Closing has no such race, so it is the cross-target-robust direct-write |
| 15 | + assertion. The surfaced Svelte race is tracked in |
| 16 | + project_vr_direct_model_write_null_react_solid_lit. |
| 17 | + |
| 18 | + The @change payload is a BARE boolean (not an object), so its Lit-consumer |
| 19 | + unwrap differs from the object-payload families (number-field/switch): the |
| 20 | + CustomEvent carries the boolean in e.detail; the typeof guard keeps the boolean |
| 21 | + primitive path on the other 5 targets from throwing on `'detail' in e`. |
| 22 | +--> |
| 23 | +<rozie name="PopoverBehaviorDemo"> |
| 24 | + |
| 25 | +<components> |
| 26 | +{ |
| 27 | + Popover: '../../packages/ui/popover/src/Popover.rozie', |
| 28 | +} |
| 29 | +</components> |
| 30 | + |
| 31 | +<data> |
| 32 | +{ |
| 33 | + panelOpen: false, |
| 34 | + lastChange: '', |
| 35 | +} |
| 36 | +</data> |
| 37 | + |
| 38 | +<script> |
| 39 | +const onChange = (e) => { |
| 40 | + const v = e && typeof e === 'object' && 'detail' in e ? e.detail : e |
| 41 | + $data.lastChange = String(v) |
| 42 | +} |
| 43 | +const applyClose = () => { |
| 44 | + $data.panelOpen = false |
| 45 | +} |
| 46 | +const valueText = () => ($data.panelOpen ? 'open' : 'closed') |
| 47 | +</script> |
| 48 | + |
| 49 | +<template> |
| 50 | +<div class="popover-demo"> |
| 51 | + <h3>Popover — behavioral</h3> |
| 52 | + |
| 53 | + <div class="controls"> |
| 54 | + <button type="button" data-testid="set-closed" @click="applyClose()">Set closed</button> |
| 55 | + <span class="readout" data-testid="readout-value">{{ valueText() }}</span> |
| 56 | + <span class="readout" data-testid="readout-change">{{ $data.lastChange }}</span> |
| 57 | + </div> |
| 58 | + |
| 59 | + <Popover |
| 60 | + r-model:open="$data.panelOpen" |
| 61 | + trigger="click" |
| 62 | + placement="bottom" |
| 63 | + :offset="8" |
| 64 | + @change="onChange($event)" |
| 65 | + > |
| 66 | + <template #anchor> |
| 67 | + <button type="button" data-testid="popover-anchor">Menu</button> |
| 68 | + </template> |
| 69 | + <div class="popover-body" data-testid="popover-content"> |
| 70 | + <p>Floating content</p> |
| 71 | + </div> |
| 72 | + </Popover> |
| 73 | +</div> |
| 74 | +</template> |
| 75 | + |
| 76 | +<style> |
| 77 | +.popover-demo { |
| 78 | + font-family: system-ui, -apple-system, sans-serif; |
| 79 | + color: #1a1a1a; |
| 80 | + padding: 1rem; |
| 81 | + width: 360px; |
| 82 | +} |
| 83 | +.popover-demo .controls { |
| 84 | + display: flex; |
| 85 | + align-items: center; |
| 86 | + gap: 0.5rem; |
| 87 | + margin-bottom: 1rem; |
| 88 | +} |
| 89 | +.popover-demo .readout { |
| 90 | + font-variant-numeric: tabular-nums; |
| 91 | + min-width: 4ch; |
| 92 | +} |
| 93 | +.popover-body { |
| 94 | + font-size: 0.9rem; |
| 95 | +} |
| 96 | +</style> |
| 97 | + |
| 98 | +</rozie> |
0 commit comments