@podoba/react 0.0.53 → 0.0.55

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@podoba/react",
3
- "version": "0.0.53",
3
+ "version": "0.0.55",
4
4
  "type": "module",
5
5
  "description": "podoba React components — React Aria Components + Tailwind primitives + layout, built with uic.",
6
6
  "repository": {
@@ -28,8 +28,8 @@
28
28
  "typecheck": "tsc --build"
29
29
  },
30
30
  "dependencies": {
31
- "@podoba/tokens": "^0.0.53",
32
- "@podoba/tailwind": "^0.0.53",
31
+ "@podoba/tokens": "^0.0.55",
32
+ "@podoba/tailwind": "^0.0.55",
33
33
  "react-aria-components": "1.20.0",
34
34
  "class-variance-authority": "0.7.1",
35
35
  "clsx": "2.1.1",
@@ -0,0 +1,25 @@
1
+ import { useLayoutEffect, useRef } from 'react'
2
+
3
+ /** Wait until dialog focus scopes and slotted controls have mounted. */
4
+ export function useFieldAutoFocus(autoFocus: boolean | undefined) {
5
+ const ref = useRef<HTMLDivElement>(null)
6
+ useLayoutEffect(() => {
7
+ if (!autoFocus) return
8
+ const previousFocus = ref.current?.ownerDocument.activeElement
9
+ const frame = requestAnimationFrame(() => {
10
+ const control = ref.current?.querySelector<HTMLInputElement | HTMLTextAreaElement>('input, textarea')
11
+ if (!control || control.disabled) return
12
+ const active = control.ownerDocument.activeElement
13
+ // Do not steal focus if the user or another field has already claimed it.
14
+ if (
15
+ active === previousFocus ||
16
+ active === control.ownerDocument.body ||
17
+ active === control.closest('[role="dialog"], [role="alertdialog"]')
18
+ ) {
19
+ control.focus({ preventScroll: true })
20
+ }
21
+ })
22
+ return () => cancelAnimationFrame(frame)
23
+ }, [autoFocus])
24
+ return ref
25
+ }
@@ -1,3 +1,4 @@
1
+ import { useFieldAutoFocus } from './field-autofocus'
1
2
  import type { ReactNode } from 'react'
2
3
  import { FieldError, Input as RACInput, Label, Text, TextField, type TextFieldProps } from 'react-aria-components'
3
4
  import { uic } from '../utils/uic'
@@ -79,21 +80,23 @@ export const Input = ({
79
80
  inputClassName,
80
81
  autoFocus,
81
82
  ...props
82
- }: InputProps) => (
83
- <TextField {...props} className={`${fieldStackClass} w-full ${rootClassName ?? ''}`}>
84
- <Label className={fieldLabelClasses[labelSize]}>{label}</Label>
85
- <StyledInput
86
- autoFocus={autoFocus}
87
- className={inputClassName}
88
- placeholder={placeholder}
89
- appearance={appearance}
90
- fieldSize={size ?? (appearance === 'filled' ? 'filled' : undefined)}
91
- />
92
- {description ? (
93
- <Text slot="description" className={fieldDescriptionClass}>
94
- {description}
95
- </Text>
96
- ) : null}
97
- <FieldError className={fieldErrorClass}>{errorMessage}</FieldError>
98
- </TextField>
99
- )
83
+ }: InputProps) => {
84
+ const fieldRef = useFieldAutoFocus(autoFocus)
85
+ return (
86
+ <TextField {...props} ref={fieldRef} className={`${fieldStackClass} w-full ${rootClassName ?? ''}`}>
87
+ <Label className={fieldLabelClasses[labelSize]}>{label}</Label>
88
+ <StyledInput
89
+ className={inputClassName}
90
+ placeholder={placeholder}
91
+ appearance={appearance}
92
+ fieldSize={size ?? (appearance === 'filled' ? 'filled' : undefined)}
93
+ />
94
+ {description ? (
95
+ <Text slot="description" className={fieldDescriptionClass}>
96
+ {description}
97
+ </Text>
98
+ ) : null}
99
+ <FieldError className={fieldErrorClass}>{errorMessage}</FieldError>
100
+ </TextField>
101
+ )
102
+ }
@@ -290,6 +290,7 @@ export function WizardFormDialog({
290
290
  isPending = false,
291
291
  isExpanded = false,
292
292
  title,
293
+ ariaLabel,
293
294
  closeLabel,
294
295
  children,
295
296
  footer,
@@ -299,6 +300,8 @@ export function WizardFormDialog({
299
300
  isPending?: boolean
300
301
  isExpanded?: boolean
301
302
  title: ReactNode
303
+ /** Stable accessible name when the visual heading changes between steps. */
304
+ ariaLabel?: string
302
305
  closeLabel: string
303
306
  children: ReactNode
304
307
  footer: ReactNode
@@ -318,7 +321,11 @@ export function WizardFormDialog({
318
321
  data-wizard-expanded={isExpanded}
319
322
  className={`h-23/25 max-h-23/25 w-24/25 max-w-24/25 min-[901px]:h-9/10 min-[901px]:max-h-288 min-[901px]:w-9/10 ${isExpanded ? 'min-[901px]:max-w-432' : 'min-[901px]:max-w-204'}`}
320
323
  >
321
- <Layout aria-labelledby={titleId} className="gap-8 py-6 min-[901px]:gap-10 min-[901px]:py-10">
324
+ <Layout
325
+ aria-label={ariaLabel}
326
+ aria-labelledby={ariaLabel ? undefined : titleId}
327
+ className="gap-8 py-6 min-[901px]:gap-10 min-[901px]:py-10"
328
+ >
322
329
  <Button
323
330
  variant="ghost"
324
331
  aria-label={closeLabel}
@@ -349,7 +356,13 @@ export function WizardFormDialog({
349
356
  </DisplayHeading>
350
357
  </Container>
351
358
  </header>
352
- <ScrollBody style={{ scrollbarGutter: 'stable' }}>
359
+ <ScrollBody
360
+ role="region"
361
+ tabIndex={0}
362
+ aria-label={ariaLabel}
363
+ aria-labelledby={ariaLabel ? undefined : titleId}
364
+ style={{ scrollbarGutter: 'stable' }}
365
+ >
353
366
  <Container className="max-w-384 px-5 min-[901px]:px-6">
354
367
  <Body className="gap-8">{children}</Body>
355
368
  </Container>
@@ -1,3 +1,4 @@
1
+ import { useFieldAutoFocus } from './field-autofocus'
1
2
  import {
2
3
  useId,
3
4
  useRef,
@@ -80,29 +81,31 @@ export const Textarea = ({
80
81
  appearance = 'outlined',
81
82
  autoFocus,
82
83
  ...props
83
- }: TextareaProps) => (
84
- // Label and gap match `Input` in both appearances (gs 17px/20px field label,
85
- // 12px to the control), so a Title + Description pair reads as one form.
86
- <TextField {...props} className={`${fieldStackClass} w-full`}>
87
- <Label className={fieldLabelClasses[labelSize]}>{label}</Label>
88
- <StyledTextArea
89
- ref={textAreaRef}
90
- onKeyDown={onTextAreaKeyDown}
91
- onInput={onTextAreaInput}
92
- autoFocus={autoFocus}
93
- className={textAreaClassName}
94
- placeholder={placeholder}
95
- rows={rows}
96
- appearance={appearance}
97
- />
98
- {description ? (
99
- <Text slot="description" className={fieldDescriptionClass}>
100
- {description}
101
- </Text>
102
- ) : null}
103
- <FieldError className={fieldErrorClass}>{errorMessage}</FieldError>
104
- </TextField>
105
- )
84
+ }: TextareaProps) => {
85
+ const fieldRef = useFieldAutoFocus(autoFocus)
86
+ return (
87
+ // Label and gap match `Input` in both appearances (gs 17px/20px field label,
88
+ // 12px to the control), so a Title + Description pair reads as one form.
89
+ <TextField {...props} ref={fieldRef} className={`${fieldStackClass} w-full`}>
90
+ <Label className={fieldLabelClasses[labelSize]}>{label}</Label>
91
+ <StyledTextArea
92
+ ref={textAreaRef}
93
+ onKeyDown={onTextAreaKeyDown}
94
+ onInput={onTextAreaInput}
95
+ className={textAreaClassName}
96
+ placeholder={placeholder}
97
+ rows={rows}
98
+ appearance={appearance}
99
+ />
100
+ {description ? (
101
+ <Text slot="description" className={fieldDescriptionClass}>
102
+ {description}
103
+ </Text>
104
+ ) : null}
105
+ <FieldError className={fieldErrorClass}>{errorMessage}</FieldError>
106
+ </TextField>
107
+ )
108
+ }
106
109
 
107
110
  export interface MentionTextareaProps {
108
111
  id?: string