Skip to content

Commit 0028d05

Browse files
committed
photo capture closed by default
1 parent 7b95a13 commit 0028d05

3 files changed

Lines changed: 15 additions & 5 deletions

File tree

src/v2/components/media/photoCapture/PhotoCapture.test.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,17 @@ describe('SolidUIPhotoCapture', () => {
7272
expect(customElements.get('solid-ui-photo-capture')).toBe(PhotoCapture)
7373
})
7474

75-
it('starts the preview inline using the default environment-facing video constraint', async () => {
75+
it('is closed by default and only starts the inline preview when opened', async () => {
7676
const photoCapture = new PhotoCapture()
7777

7878
document.body.appendChild(photoCapture)
7979
await photoCapture.updateComplete
80+
81+
expect(photoCapture.open).toBe(false)
82+
expect(getUserMedia).not.toHaveBeenCalled()
83+
84+
photoCapture.open = true
85+
await photoCapture.updateComplete
8086
await Promise.resolve()
8187
await photoCapture.updateComplete
8288

@@ -90,12 +96,14 @@ describe('SolidUIPhotoCapture', () => {
9096
it('accepts dialog presentation and custom constraints JSON', async () => {
9197
const photoCapture = new PhotoCapture()
9298
photoCapture.presentation = 'dialog'
93-
photoCapture.open = false
9499
photoCapture.constraints = JSON.stringify({ video: true, audio: false })
95100

96101
document.body.appendChild(photoCapture)
97102
await photoCapture.updateComplete
98103

104+
expect(photoCapture.open).toBe(false)
105+
expect(HTMLDialogElement.prototype.showModal).not.toHaveBeenCalled()
106+
99107
const trigger = photoCapture.shadowRoot?.querySelector('button.trigger-button') as HTMLButtonElement
100108
trigger.click()
101109
await photoCapture.updateComplete
@@ -111,6 +119,7 @@ describe('SolidUIPhotoCapture', () => {
111119
const photoCapture = new PhotoCapture()
112120
const captured = jest.fn()
113121
const changed = jest.fn()
122+
photoCapture.open = true
114123

115124
photoCapture.addEventListener('photo-captured', (event: Event) => {
116125
captured((event as CustomEvent).detail)
@@ -147,6 +156,7 @@ describe('SolidUIPhotoCapture', () => {
147156
it('can participate in a form-like submission while still exposing a value property', async () => {
148157
const form = document.createElement('form')
149158
const photoCapture = new PhotoCapture()
159+
photoCapture.open = true
150160
photoCapture.name = 'avatar'
151161
form.appendChild(photoCapture)
152162
document.body.appendChild(form)

src/v2/components/media/photoCapture/PhotoCapture.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ export class PhotoCapture extends LitElement {
322322
this.constraints = ''
323323
this.captureFormat = DEFAULT_CAPTURE_FORMAT
324324
this.captureQuality = undefined
325-
this.open = true
325+
this.open = false
326326
this.disabled = false
327327
this.name = ''
328328
this.required = false

src/v2/components/media/photoCapture/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ The legacy flat import path `solid-ui/components/photo-capture` still works, but
4040
| `label` | `label` | `string` | `Take Photo` | Trigger button label. Ignored when `show-trigger` is false and `presentation="inline"`. |
4141
| `heading` | `heading` | `string` | `Take a photo` | Panel heading. |
4242
| `presentation` | `presentation` | `'inline' \| 'dialog'` | `'inline'` | Controls whether the capture UI sits in-page or inside a native dialog. |
43-
| `open` | `open` | `boolean` | `true` | Controls whether the capture panel is visible. |
43+
| `open` | `open` | `boolean` | `false` | Controls whether the capture panel is visible. |
4444
| `name` | `name` | `string` | `''` | Form field name used when the component participates in form submission. |
4545
| `required` | `required` | `boolean` | `false` | Marks the control as required for form validation. |
4646
| `value` | none | `File \| null` | `null` | The current captured file. Settable from JavaScript. |
@@ -74,7 +74,7 @@ The legacy flat import path `solid-ui/components/photo-capture` still works, but
7474

7575
## Notes
7676

77-
- Inline mode is the default, so the component can be embedded directly inside a page or form.
77+
- Inline mode is the default presentation, and the panel starts closed until `open` is set or the trigger button is used.
7878
- Dialog mode uses the native `<dialog>` element and is useful when the capture flow should float above the current page.
7979
- The component does not upload the photo itself. Consumers can persist it by reading `value`, listening for `change`, or handling `photo-captured`.
8080
- When form-associated custom elements are supported, the component uses `ElementInternals`. Otherwise it still supports form-style submission via the form's `formdata` event.

0 commit comments

Comments
 (0)