@cognitap/radiant 0.0.77 → 0.0.79
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/CHANGELOG.md +36 -2
- package/README.md +6 -3
- package/RELEASE_POLICY.md +8 -19
- package/dist/library/charts/Charts.d.ts.map +1 -1
- package/dist/library/charts/Charts.js +6 -2
- package/dist/library/charts/Charts.js.map +1 -1
- package/dist/library/components/Accordion/Accordion.js +1 -1
- package/dist/library/components/Accordion/Accordion.js.map +1 -1
- package/dist/library/components/Alert/Alert.js +1 -1
- package/dist/library/components/Alert/Alert.js.map +1 -1
- package/dist/library/components/AppShell/AppShell.d.ts.map +1 -1
- package/dist/library/components/AppShell/AppShell.js +7 -6
- package/dist/library/components/AppShell/AppShell.js.map +1 -1
- package/dist/library/components/AspectRatio/AspectRatio.js +1 -1
- package/dist/library/components/AspectRatio/AspectRatio.js.map +1 -1
- package/dist/library/components/Avatar/Avatar.js +1 -1
- package/dist/library/components/Avatar/Avatar.js.map +1 -1
- package/dist/library/components/Badge/Badge.js +1 -1
- package/dist/library/components/Badge/Badge.js.map +1 -1
- package/dist/library/components/Breadcrumb/Breadcrumb.d.ts +2 -1
- package/dist/library/components/Breadcrumb/Breadcrumb.d.ts.map +1 -1
- package/dist/library/components/Breadcrumb/Breadcrumb.js +5 -10
- package/dist/library/components/Breadcrumb/Breadcrumb.js.map +1 -1
- package/dist/library/components/Button/Button.js +1 -1
- package/dist/library/components/Button/Button.js.map +1 -1
- package/dist/library/components/ButtonGroup/ButtonGroup.js +1 -1
- package/dist/library/components/ButtonGroup/ButtonGroup.js.map +1 -1
- package/dist/library/components/Card/Card.js +1 -1
- package/dist/library/components/Card/Card.js.map +1 -1
- package/dist/library/components/Carousel/Carousel.d.ts.map +1 -1
- package/dist/library/components/Carousel/Carousel.js +11 -9
- package/dist/library/components/Carousel/Carousel.js.map +1 -1
- package/dist/library/components/Checkbox/Checkbox.d.ts +3 -1
- package/dist/library/components/Checkbox/Checkbox.d.ts.map +1 -1
- package/dist/library/components/Checkbox/Checkbox.js +8 -8
- package/dist/library/components/Checkbox/Checkbox.js.map +1 -1
- package/dist/library/components/CheckboxGroup/CheckboxGroup.js +1 -1
- package/dist/library/components/CheckboxGroup/CheckboxGroup.js.map +1 -1
- package/dist/library/components/CodeBlock/CodeBlock.js +3 -3
- package/dist/library/components/CodeBlock/CodeBlock.js.map +1 -1
- package/dist/library/components/Collapsible/Collapsible.d.ts.map +1 -1
- package/dist/library/components/Collapsible/Collapsible.js +4 -6
- package/dist/library/components/Collapsible/Collapsible.js.map +1 -1
- package/dist/library/components/Combobox/Combobox.d.ts +9 -1
- package/dist/library/components/Combobox/Combobox.d.ts.map +1 -1
- package/dist/library/components/Combobox/Combobox.js +14 -13
- package/dist/library/components/Combobox/Combobox.js.map +1 -1
- package/dist/library/components/Combobox/comboboxStyles.d.ts.map +1 -1
- package/dist/library/components/Combobox/comboboxStyles.js +5 -2
- package/dist/library/components/Combobox/comboboxStyles.js.map +1 -1
- package/dist/library/components/Command/Command.d.ts +1 -4
- package/dist/library/components/Command/Command.d.ts.map +1 -1
- package/dist/library/components/Command/Command.js +3 -9
- package/dist/library/components/Command/Command.js.map +1 -1
- package/dist/library/components/ContextMenu/ContextMenu.d.ts.map +1 -1
- package/dist/library/components/ContextMenu/ContextMenu.js +3 -2
- package/dist/library/components/ContextMenu/ContextMenu.js.map +1 -1
- package/dist/library/components/Dialog/Dialog.d.ts +3 -0
- package/dist/library/components/Dialog/Dialog.d.ts.map +1 -1
- package/dist/library/components/Dialog/Dialog.js +9 -10
- package/dist/library/components/Dialog/Dialog.js.map +1 -1
- package/dist/library/components/Drawer/Drawer.js +1 -1
- package/dist/library/components/Drawer/Drawer.js.map +1 -1
- package/dist/library/components/EmptyState/EmptyState.js +1 -1
- package/dist/library/components/EmptyState/EmptyState.js.map +1 -1
- package/dist/library/components/Field/Field.js +1 -1
- package/dist/library/components/Field/Field.js.map +1 -1
- package/dist/library/components/Fieldset/Fieldset.d.ts +1 -1
- package/dist/library/components/Fieldset/Fieldset.d.ts.map +1 -1
- package/dist/library/components/Fieldset/Fieldset.js +3 -3
- package/dist/library/components/Fieldset/Fieldset.js.map +1 -1
- package/dist/library/components/FileInput/FileInput.d.ts +3 -1
- package/dist/library/components/FileInput/FileInput.d.ts.map +1 -1
- package/dist/library/components/FileInput/FileInput.js +6 -4
- package/dist/library/components/FileInput/FileInput.js.map +1 -1
- package/dist/library/components/Form/Form.d.ts.map +1 -1
- package/dist/library/components/Form/Form.js +16 -11
- package/dist/library/components/Form/Form.js.map +1 -1
- package/dist/library/components/HoverCard/HoverCard.d.ts +1 -0
- package/dist/library/components/HoverCard/HoverCard.d.ts.map +1 -1
- package/dist/library/components/HoverCard/HoverCard.js +2 -1
- package/dist/library/components/HoverCard/HoverCard.js.map +1 -1
- package/dist/library/components/InlineCode/InlineCode.js +1 -1
- package/dist/library/components/InlineCode/InlineCode.js.map +1 -1
- package/dist/library/components/Input/Input.d.ts +3 -1
- package/dist/library/components/Input/Input.d.ts.map +1 -1
- package/dist/library/components/Input/Input.js +7 -12
- package/dist/library/components/Input/Input.js.map +1 -1
- package/dist/library/components/InputGroup/InputGroup.d.ts.map +1 -1
- package/dist/library/components/InputGroup/InputGroup.js +3 -2
- package/dist/library/components/InputGroup/InputGroup.js.map +1 -1
- package/dist/library/components/Kbd/Kbd.js +1 -1
- package/dist/library/components/Kbd/Kbd.js.map +1 -1
- package/dist/library/components/Link/Link.d.ts +4 -2
- package/dist/library/components/Link/Link.d.ts.map +1 -1
- package/dist/library/components/Link/Link.js +7 -4
- package/dist/library/components/Link/Link.js.map +1 -1
- package/dist/library/components/Menu/Menu.d.ts +13 -3
- package/dist/library/components/Menu/Menu.d.ts.map +1 -1
- package/dist/library/components/Menu/Menu.js +24 -9
- package/dist/library/components/Menu/Menu.js.map +1 -1
- package/dist/library/components/Menubar/Menubar.d.ts.map +1 -1
- package/dist/library/components/Menubar/Menubar.js +2 -2
- package/dist/library/components/Menubar/Menubar.js.map +1 -1
- package/dist/library/components/Meter/Meter.js +1 -1
- package/dist/library/components/Meter/Meter.js.map +1 -1
- package/dist/library/components/NativeSelect/NativeSelect.d.ts.map +1 -1
- package/dist/library/components/NativeSelect/NativeSelect.js +3 -2
- package/dist/library/components/NativeSelect/NativeSelect.js.map +1 -1
- package/dist/library/components/NavLink/NavLink.d.ts.map +1 -1
- package/dist/library/components/NavLink/NavLink.js +6 -4
- package/dist/library/components/NavLink/NavLink.js.map +1 -1
- package/dist/library/components/NavigationMenu/NavigationMenu.d.ts +1 -1
- package/dist/library/components/NavigationMenu/NavigationMenu.d.ts.map +1 -1
- package/dist/library/components/NavigationMenu/NavigationMenu.js +11 -4
- package/dist/library/components/NavigationMenu/NavigationMenu.js.map +1 -1
- package/dist/library/components/NumberField/NumberField.d.ts.map +1 -1
- package/dist/library/components/NumberField/NumberField.js +2 -2
- package/dist/library/components/NumberField/NumberField.js.map +1 -1
- package/dist/library/components/OTPField/OTPField.d.ts.map +1 -1
- package/dist/library/components/OTPField/OTPField.js +3 -2
- package/dist/library/components/OTPField/OTPField.js.map +1 -1
- package/dist/library/components/Pagination/Pagination.d.ts +2 -1
- package/dist/library/components/Pagination/Pagination.d.ts.map +1 -1
- package/dist/library/components/Pagination/Pagination.js +5 -7
- package/dist/library/components/Pagination/Pagination.js.map +1 -1
- package/dist/library/components/PasswordInput/PasswordInput.js +1 -1
- package/dist/library/components/PasswordInput/PasswordInput.js.map +1 -1
- package/dist/library/components/Popover/Popover.d.ts.map +1 -1
- package/dist/library/components/Popover/Popover.js +5 -3
- package/dist/library/components/Popover/Popover.js.map +1 -1
- package/dist/library/components/Progress/Progress.js +1 -1
- package/dist/library/components/Progress/Progress.js.map +1 -1
- package/dist/library/components/RadioGroup/RadioGroup.d.ts +4 -2
- package/dist/library/components/RadioGroup/RadioGroup.d.ts.map +1 -1
- package/dist/library/components/RadioGroup/RadioGroup.js +10 -11
- package/dist/library/components/RadioGroup/RadioGroup.js.map +1 -1
- package/dist/library/components/Resizable/Resizable.d.ts.map +1 -1
- package/dist/library/components/Resizable/Resizable.js +3 -2
- package/dist/library/components/Resizable/Resizable.js.map +1 -1
- package/dist/library/components/ScrollArea/ScrollArea.d.ts.map +1 -1
- package/dist/library/components/ScrollArea/ScrollArea.js +3 -2
- package/dist/library/components/ScrollArea/ScrollArea.js.map +1 -1
- package/dist/library/components/Select/Select.d.ts +7 -0
- package/dist/library/components/Select/Select.d.ts.map +1 -1
- package/dist/library/components/Select/Select.js +12 -11
- package/dist/library/components/Select/Select.js.map +1 -1
- package/dist/library/components/Select/selectStyles.d.ts.map +1 -1
- package/dist/library/components/Select/selectStyles.js +3 -1
- package/dist/library/components/Select/selectStyles.js.map +1 -1
- package/dist/library/components/Separator/Separator.js +1 -1
- package/dist/library/components/Separator/Separator.js.map +1 -1
- package/dist/library/components/Skeleton/Skeleton.js +1 -1
- package/dist/library/components/Skeleton/Skeleton.js.map +1 -1
- package/dist/library/components/Slider/Slider.d.ts +3 -1
- package/dist/library/components/Slider/Slider.d.ts.map +1 -1
- package/dist/library/components/Slider/Slider.js +7 -9
- package/dist/library/components/Slider/Slider.js.map +1 -1
- package/dist/library/components/Spinner/Spinner.js +1 -1
- package/dist/library/components/Spinner/Spinner.js.map +1 -1
- package/dist/library/components/Switch/Switch.d.ts +3 -1
- package/dist/library/components/Switch/Switch.d.ts.map +1 -1
- package/dist/library/components/Switch/Switch.js +7 -8
- package/dist/library/components/Switch/Switch.js.map +1 -1
- package/dist/library/components/Table/Table.d.ts.map +1 -1
- package/dist/library/components/Table/Table.js +3 -2
- package/dist/library/components/Table/Table.js.map +1 -1
- package/dist/library/components/Tabs/Tabs.d.ts.map +1 -1
- package/dist/library/components/Tabs/Tabs.js +9 -7
- package/dist/library/components/Tabs/Tabs.js.map +1 -1
- package/dist/library/components/Tag/Tag.js +1 -1
- package/dist/library/components/Tag/Tag.js.map +1 -1
- package/dist/library/components/TagsInput/TagsInput.d.ts +3 -1
- package/dist/library/components/TagsInput/TagsInput.d.ts.map +1 -1
- package/dist/library/components/TagsInput/TagsInput.js +9 -6
- package/dist/library/components/TagsInput/TagsInput.js.map +1 -1
- package/dist/library/components/Textarea/Textarea.d.ts +3 -1
- package/dist/library/components/Textarea/Textarea.d.ts.map +1 -1
- package/dist/library/components/Textarea/Textarea.js +7 -8
- package/dist/library/components/Textarea/Textarea.js.map +1 -1
- package/dist/library/components/ThemeScope/ThemeScope.js +1 -1
- package/dist/library/components/ThemeScope/ThemeScope.js.map +1 -1
- package/dist/library/components/Toast/Toast.d.ts +2 -1
- package/dist/library/components/Toast/Toast.d.ts.map +1 -1
- package/dist/library/components/Toast/Toast.js +22 -9
- package/dist/library/components/Toast/Toast.js.map +1 -1
- package/dist/library/components/ToggleGroup/ToggleGroup.js +3 -1
- package/dist/library/components/ToggleGroup/ToggleGroup.js.map +1 -1
- package/dist/library/components/Toolbar/Toolbar.js +1 -1
- package/dist/library/components/Toolbar/Toolbar.js.map +1 -1
- package/dist/library/components/Tooltip/Tooltip.d.ts +1 -0
- package/dist/library/components/Tooltip/Tooltip.d.ts.map +1 -1
- package/dist/library/components/Tooltip/Tooltip.js +2 -2
- package/dist/library/components/Tooltip/Tooltip.js.map +1 -1
- package/dist/library/components/shared/actionStyles.d.ts.map +1 -1
- package/dist/library/components/shared/actionStyles.js +3 -1
- package/dist/library/components/shared/actionStyles.js.map +1 -1
- package/dist/library/components/shared/focusStyles.d.ts +13 -0
- package/dist/library/components/shared/focusStyles.d.ts.map +1 -0
- package/dist/library/components/shared/focusStyles.js +17 -0
- package/dist/library/components/shared/focusStyles.js.map +1 -0
- package/dist/library/index.d.ts +1 -1
- package/dist/library/index.d.ts.map +1 -1
- package/dist/library/index.js.map +1 -1
- package/dist/library/motion/MotionLink.js +1 -1
- package/dist/library/motion/MotionLink.js.map +1 -1
- package/dist/library/react/useComboboxPopup.d.ts.map +1 -1
- package/dist/library/react/useComboboxPopup.js +45 -6
- package/dist/library/react/useComboboxPopup.js.map +1 -1
- package/dist/library/react/useRovingFocus.d.ts.map +1 -1
- package/dist/library/react/useRovingFocus.js +76 -11
- package/dist/library/react/useRovingFocus.js.map +1 -1
- package/dist/library/react/useToastTimer.d.ts.map +1 -1
- package/dist/library/react/useToastTimer.js +29 -10
- package/dist/library/react/useToastTimer.js.map +1 -1
- package/dist/library/styles.css +1 -1
- package/dist/library/themes/components.d.ts +12 -0
- package/dist/library/themes/components.d.ts.map +1 -1
- package/dist/library/themes/components.js +15 -3
- package/dist/library/themes/components.js.map +1 -1
- package/docs/accessibility.md +23 -111
- package/docs/architecture.md +48 -228
- package/docs/motion.md +65 -130
- package/docs/theming.md +51 -422
- package/package.json +21 -13
- package/src/charts/Charts.tsx +6 -3
- package/src/components/Accordion/Accordion.tsx +1 -1
- package/src/components/Alert/Alert.tsx +1 -1
- package/src/components/AppShell/AppShell.tsx +10 -6
- package/src/components/AspectRatio/AspectRatio.tsx +1 -1
- package/src/components/Avatar/Avatar.tsx +1 -1
- package/src/components/Badge/Badge.tsx +1 -1
- package/src/components/Breadcrumb/Breadcrumb.tsx +6 -10
- package/src/components/Button/Button.tsx +1 -1
- package/src/components/ButtonGroup/ButtonGroup.tsx +1 -1
- package/src/components/Card/Card.tsx +1 -1
- package/src/components/Carousel/Carousel.tsx +14 -9
- package/src/components/Checkbox/Checkbox.tsx +10 -7
- package/src/components/CheckboxGroup/CheckboxGroup.tsx +1 -1
- package/src/components/CodeBlock/CodeBlock.tsx +3 -3
- package/src/components/Collapsible/Collapsible.tsx +4 -6
- package/src/components/Combobox/Combobox.tsx +72 -16
- package/src/components/Combobox/comboboxStyles.ts +5 -2
- package/src/components/Command/Command.tsx +3 -10
- package/src/components/ContextMenu/ContextMenu.tsx +3 -5
- package/src/components/Dialog/Dialog.tsx +30 -14
- package/src/components/Drawer/Drawer.tsx +1 -1
- package/src/components/EmptyState/EmptyState.tsx +1 -1
- package/src/components/Field/Field.tsx +1 -1
- package/src/components/Fieldset/Fieldset.tsx +4 -4
- package/src/components/FileInput/FileInput.tsx +9 -3
- package/src/components/Form/Form.tsx +14 -10
- package/src/components/HoverCard/HoverCard.tsx +6 -2
- package/src/components/InlineCode/InlineCode.tsx +1 -1
- package/src/components/Input/Input.tsx +14 -13
- package/src/components/InputGroup/InputGroup.tsx +5 -3
- package/src/components/Kbd/Kbd.tsx +1 -1
- package/src/components/Link/Link.tsx +10 -4
- package/src/components/Menu/Menu.tsx +52 -10
- package/src/components/Menubar/Menubar.tsx +2 -1
- package/src/components/Meter/Meter.tsx +1 -1
- package/src/components/NativeSelect/NativeSelect.tsx +4 -2
- package/src/components/NavLink/NavLink.tsx +9 -6
- package/src/components/NavigationMenu/NavigationMenu.tsx +15 -12
- package/src/components/NumberField/NumberField.tsx +2 -1
- package/src/components/OTPField/OTPField.tsx +5 -2
- package/src/components/Pagination/Pagination.tsx +6 -8
- package/src/components/PasswordInput/PasswordInput.tsx +1 -1
- package/src/components/Popover/Popover.tsx +5 -2
- package/src/components/Progress/Progress.tsx +1 -1
- package/src/components/RadioGroup/RadioGroup.tsx +14 -8
- package/src/components/Resizable/Resizable.tsx +5 -3
- package/src/components/ScrollArea/ScrollArea.tsx +3 -2
- package/src/components/Select/Select.tsx +28 -14
- package/src/components/Select/selectStyles.ts +3 -1
- package/src/components/Separator/Separator.tsx +1 -1
- package/src/components/Skeleton/Skeleton.tsx +1 -1
- package/src/components/Slider/Slider.tsx +9 -8
- package/src/components/Spinner/Spinner.tsx +1 -1
- package/src/components/Switch/Switch.tsx +9 -7
- package/src/components/Table/Table.tsx +4 -2
- package/src/components/Tabs/Tabs.tsx +9 -8
- package/src/components/Tag/Tag.tsx +1 -1
- package/src/components/TagsInput/TagsInput.tsx +11 -4
- package/src/components/Textarea/Textarea.tsx +9 -7
- package/src/components/ThemeScope/ThemeScope.tsx +1 -1
- package/src/components/Toast/Toast.tsx +27 -12
- package/src/components/ToggleGroup/ToggleGroup.tsx +3 -1
- package/src/components/Toolbar/Toolbar.tsx +1 -1
- package/src/components/Tooltip/Tooltip.tsx +3 -2
- package/src/components/shared/actionStyles.ts +3 -1
- package/src/components/shared/focusStyles.ts +28 -0
- package/src/css.d.ts +2 -0
- package/src/index.ts +1 -0
- package/src/motion/MotionLink.tsx +1 -1
- package/src/react/useComboboxPopup.ts +38 -6
- package/src/react/useRovingFocus.ts +73 -8
- package/src/react/useToastTimer.ts +25 -10
- package/src/styles.d.ts +1 -0
- package/src/themes/baseline.css +1 -1
- package/src/themes/components.ts +15 -3
- package/src/typography.css +17 -12
- package/dist/library/cn.d.ts +0 -3
- package/dist/library/cn.d.ts.map +0 -1
- package/dist/library/cn.js +0 -370
- package/dist/library/cn.js.map +0 -1
- package/src/cn.ts +0 -372
|
@@ -2,13 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
import type { ComponentProps } from 'react'
|
|
4
4
|
import { cva } from 'class-variance-authority'
|
|
5
|
-
import { cn } from '
|
|
5
|
+
import { cn } from 'cn'
|
|
6
|
+
import { joinIds } from '../../internal/ids.js'
|
|
6
7
|
import { controlBorderClass, controlMetrics } from '../shared/controlStyles.js'
|
|
7
8
|
import { useNativeOwner, type ValueOwner } from '../../react/useNativeOwner.js'
|
|
8
9
|
import type { ThemeStyle } from '../../themes/defineTheme.js'
|
|
9
10
|
import type { ControlSize } from '../../presentation.js'
|
|
10
11
|
import { useFieldControl } from '../Field/Field.js'
|
|
11
12
|
import { scrollbarClass } from '../shared/scrollbarStyles.js'
|
|
13
|
+
import { focusRingClass } from '../shared/focusStyles.js'
|
|
12
14
|
|
|
13
15
|
const textareaVariants = cva([
|
|
14
16
|
controlBorderClass,
|
|
@@ -31,11 +33,8 @@ const textareaVariants = cva([
|
|
|
31
33
|
'[corner-shape:var(--rad-textarea-corner-shape,var(--rad-control-corner-shape,round))]',
|
|
32
34
|
'[box-shadow:var(--rad-textarea-shadow,var(--rad-control-field-shadow,none))] [backdrop-filter:var(--rad-control-field-backdrop-filter,none)]',
|
|
33
35
|
'placeholder:[color:var(--rad-textarea-placeholder,var(--rad-color-placeholder,oklch(0.5_0.01_286)))]',
|
|
34
|
-
|
|
35
|
-
'focus-visible:[
|
|
36
|
-
'focus-visible:[outline-width:var(--rad-textarea-focus-width,var(--rad-focus-width,2px))]',
|
|
37
|
-
'focus-visible:[outline-offset:var(--rad-textarea-focus-offset,var(--rad-focus-offset,2px))]',
|
|
38
|
-
'focus-visible:[outline-style:var(--rad-textarea-focus-style,var(--rad-focus-style,solid))]',
|
|
36
|
+
focusRingClass,
|
|
37
|
+
'focus-visible:[--_rad-focus-color:var(--rad-textarea-focus-color)] focus-visible:[--_rad-focus-width:var(--rad-textarea-focus-width)] focus-visible:[--_rad-focus-offset:var(--rad-textarea-focus-offset)] focus-visible:[--_rad-focus-style:var(--rad-textarea-focus-style)]',
|
|
39
38
|
'data-invalid:[border-color:var(--rad-textarea-invalid-border,var(--rad-color-invalid,oklch(0.56_0.19_25)))]',
|
|
40
39
|
'disabled:cursor-not-allowed',
|
|
41
40
|
'disabled:[background:var(--rad-textarea-disabled-background,var(--rad-color-disabled-background,oklch(0.96_0.005_286)))]',
|
|
@@ -54,6 +53,8 @@ export type TextareaProps = Omit<
|
|
|
54
53
|
controlSize?: ControlSize
|
|
55
54
|
/** Applied to the native textarea, including caller-owned motion styles. */
|
|
56
55
|
style?: ThemeStyle
|
|
56
|
+
/** Additional composed identities; the textarea token is always retained. */
|
|
57
|
+
'data-slot'?: string
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
/** Native editing, selection, events and ref; Field supplies owned form relationships. */
|
|
@@ -78,6 +79,7 @@ export function TextareaRoot({
|
|
|
78
79
|
'aria-describedby': ariaDescribedBy,
|
|
79
80
|
'aria-invalid': ariaInvalid,
|
|
80
81
|
'aria-required': ariaRequired,
|
|
82
|
+
'data-slot': slot,
|
|
81
83
|
...props
|
|
82
84
|
}: TextareaProps & { family?: 'input-group-textarea' }) {
|
|
83
85
|
useNativeOwner('Textarea', props.value, props.defaultValue)
|
|
@@ -98,7 +100,7 @@ export function TextareaRoot({
|
|
|
98
100
|
{...control}
|
|
99
101
|
className={cn(textareaVariants(), controlMetrics({ controlSize }), className)}
|
|
100
102
|
data-control-size={controlSize}
|
|
101
|
-
data-slot={
|
|
103
|
+
data-slot={joinIds('textarea', family, slot)}
|
|
102
104
|
rows={rows}
|
|
103
105
|
/>
|
|
104
106
|
)
|
|
@@ -4,7 +4,7 @@ import { MotionProfileContext } from '../../motion/context.js'
|
|
|
4
4
|
|
|
5
5
|
import { createContext, useContext } from 'react'
|
|
6
6
|
import type { ComponentProps } from 'react'
|
|
7
|
-
import { cn } from '
|
|
7
|
+
import { cn } from 'cn'
|
|
8
8
|
import { defaultTheme } from '../../themes/default.js'
|
|
9
9
|
import { modeStyle } from '../../themes/tokens.js'
|
|
10
10
|
import type { Theme, ThemeMode, ThemeStyle } from '../../themes/defineTheme.js'
|
|
@@ -21,8 +21,9 @@ import {
|
|
|
21
21
|
type AlertDescriptionProps
|
|
22
22
|
} from '../Alert/Alert.js'
|
|
23
23
|
import { Button, type ButtonProps, type ButtonRenderProps } from '../Button/Button.js'
|
|
24
|
-
import { cn } from '
|
|
24
|
+
import { cn } from 'cn'
|
|
25
25
|
import { joinIds } from '../../internal/ids.js'
|
|
26
|
+
import { requireAccessibleName, type AccessibleName } from '../../internal/accessibleName.js'
|
|
26
27
|
import type { WithoutToggle } from '../../internal/types.js'
|
|
27
28
|
import { composeAction } from '../../internal/events.js'
|
|
28
29
|
import { validateToastDuration } from '../../internal/toast.js'
|
|
@@ -33,6 +34,7 @@ import { useToastTimer } from '../../react/useToastTimer.js'
|
|
|
33
34
|
import { useTransitionHost } from '../../motion/host.js'
|
|
34
35
|
import type { ThemeStyle } from '../../themes/defineTheme.js'
|
|
35
36
|
import { scrollbarClass } from '../shared/scrollbarStyles.js'
|
|
37
|
+
import { focusRingClass } from '../shared/focusStyles.js'
|
|
36
38
|
|
|
37
39
|
export type ToastProviderProps = { duration?: number; children?: ReactNode }
|
|
38
40
|
export type ToastAnnouncement = AlertAnnouncement
|
|
@@ -63,7 +65,8 @@ export type ToastRenderProps = ButtonRenderProps
|
|
|
63
65
|
export type ToastViewportProps = Omit<
|
|
64
66
|
ComponentProps<'section'>,
|
|
65
67
|
'style' | 'role' | 'tabIndex' | 'aria-keyshortcuts'
|
|
66
|
-
> &
|
|
68
|
+
> &
|
|
69
|
+
AccessibleName & { style?: ThemeStyle; 'data-slot'?: string; hotkey?: boolean }
|
|
67
70
|
type Queue = {
|
|
68
71
|
duration: number
|
|
69
72
|
queue: string[]
|
|
@@ -188,15 +191,22 @@ export function Toast({
|
|
|
188
191
|
if (!['off', 'polite', 'assertive'].includes(announce))
|
|
189
192
|
throw new TypeError('Toast announce must be off, polite or assertive.')
|
|
190
193
|
const nodeRef = useRef<HTMLDivElement>(null)
|
|
191
|
-
const [label, setLabel] = useState('
|
|
194
|
+
const [label, setLabel] = useState('')
|
|
192
195
|
const focused = useRef(false)
|
|
193
196
|
const returnTo = useRef<HTMLElement | null>(null)
|
|
194
197
|
const update = useRef(() => {})
|
|
195
|
-
const
|
|
198
|
+
const ariaLabel = props['aria-label'],
|
|
199
|
+
ariaLabelledBy = props['aria-labelledby']
|
|
200
|
+
const named = { 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy }
|
|
201
|
+
const latest = useRef({ announce, announcement, named })
|
|
196
202
|
useLayoutEffect(() => {
|
|
197
|
-
latest.current = {
|
|
203
|
+
latest.current = {
|
|
204
|
+
announce,
|
|
205
|
+
announcement,
|
|
206
|
+
named: { 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy }
|
|
207
|
+
}
|
|
198
208
|
update.current()
|
|
199
|
-
}, [announce, announcement])
|
|
209
|
+
}, [announce, announcement, ariaLabel, ariaLabelledBy])
|
|
200
210
|
useLayoutEffect(() => (state.value ? register(id) : undefined), [state.value, register, id])
|
|
201
211
|
useLayoutEffect(() => {
|
|
202
212
|
const node = nodeRef.current
|
|
@@ -211,7 +221,8 @@ export function Toast({
|
|
|
211
221
|
)
|
|
212
222
|
)
|
|
213
223
|
const title = parts.find(part => part.dataset.slot?.split(' ').includes('toast-title'))
|
|
214
|
-
|
|
224
|
+
const name = title?.innerText.trim() ?? ''
|
|
225
|
+
setLabel(name)
|
|
215
226
|
const text =
|
|
216
227
|
latest.current.announcement ??
|
|
217
228
|
parts
|
|
@@ -219,9 +230,11 @@ export function Toast({
|
|
|
219
230
|
.filter(Boolean)
|
|
220
231
|
.join(' ')
|
|
221
232
|
announceText(id, text, latest.current.announce, win)
|
|
233
|
+
return name
|
|
222
234
|
}
|
|
223
235
|
update.current = publish
|
|
224
|
-
|
|
236
|
+
// A toast is named by its ToastTitle unless the consumer names it.
|
|
237
|
+
if (!publish()) requireAccessibleName('Toast without a ToastTitle', latest.current.named)
|
|
225
238
|
const observer = new win.MutationObserver(publish)
|
|
226
239
|
observer.observe(node, { childList: true, subtree: true, characterData: true })
|
|
227
240
|
return () => {
|
|
@@ -252,21 +265,23 @@ export function Toast({
|
|
|
252
265
|
{...props}
|
|
253
266
|
ref={transitionRef}
|
|
254
267
|
announce="off"
|
|
255
|
-
aria-label={
|
|
268
|
+
aria-label={
|
|
269
|
+
props['aria-label'] ?? (props['aria-labelledby'] ? undefined : label || undefined)
|
|
270
|
+
}
|
|
256
271
|
hidden={!visible}
|
|
257
272
|
inert={!visible}
|
|
258
273
|
aria-hidden={!visible || undefined}
|
|
259
274
|
tabIndex={-1}
|
|
260
275
|
data-slot={joinIds('toast', props['data-slot'])}
|
|
261
276
|
data-state={visible ? 'open' : 'closed'}
|
|
262
|
-
data-queued={
|
|
277
|
+
data-queued={state.value && !visible ? '' : undefined}
|
|
263
278
|
data-motion={motion}
|
|
264
279
|
data-urgency={announce}
|
|
265
280
|
className={cn(
|
|
266
281
|
'[&[hidden]]:hidden pointer-events-auto max-h-[calc(100dvh-2rem)] overflow-auto overscroll-contain outline-none p-[var(--rad-toast-padding,var(--rad-surface-padding,1.5rem))] gap-[var(--rad-toast-gap,var(--rad-spacing-header-gap,0.375rem))] rounded-[var(--rad-toast-radius,var(--rad-surface-radius,0.75rem))]',
|
|
267
282
|
scrollbarClass,
|
|
268
283
|
'bg-[var(--rad-toast-background,var(--_action-soft))] [color:var(--rad-toast-color,var(--_action-ink))] [border-color:var(--rad-toast-border-color,var(--_action-edge))] [border-width:var(--rad-toast-border-width,var(--rad-surface-border-width,1px))] [border-style:var(--rad-toast-border-style,var(--rad-surface-border-style,solid))] [box-shadow:var(--rad-toast-shadow,var(--rad-surface-overlay-shadow,0_24px_64px_-16px_rgb(0_0_0/0.3)))]',
|
|
269
|
-
|
|
284
|
+
focusRingClass,
|
|
270
285
|
'forced-colors:border-[CanvasText] forced-colors:bg-[Canvas] forced-colors:text-[CanvasText] forced-colors:shadow-none',
|
|
271
286
|
active && !off && 'opacity-[var(--_rad-popup-enter,0)] motion-reduce:opacity-100',
|
|
272
287
|
className
|
|
@@ -348,6 +363,7 @@ export function ToastClose({ onClick, ...props }: ToastCloseProps) {
|
|
|
348
363
|
)
|
|
349
364
|
}
|
|
350
365
|
export function ToastViewport({ hotkey = true, ref, className, ...props }: ToastViewportProps) {
|
|
366
|
+
requireAccessibleName('ToastViewport', props)
|
|
351
367
|
useQueue()
|
|
352
368
|
const nativeProps = { ...props, role: undefined }
|
|
353
369
|
const nodeRef = useRef<HTMLElement>(null)
|
|
@@ -381,7 +397,6 @@ export function ToastViewport({ hotkey = true, ref, className, ...props }: Toast
|
|
|
381
397
|
<section
|
|
382
398
|
{...nativeProps}
|
|
383
399
|
ref={host}
|
|
384
|
-
aria-label={props['aria-labelledby'] ? undefined : (props['aria-label'] ?? 'Notifications')}
|
|
385
400
|
aria-keyshortcuts={hotkey ? 'F8' : undefined}
|
|
386
401
|
tabIndex={-1}
|
|
387
402
|
data-slot={joinIds('toast-viewport', props['data-slot'])}
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
} from 'react'
|
|
12
12
|
import { Button, type ButtonProps, type ButtonRenderProps } from '../Button/Button.js'
|
|
13
13
|
import { requireAccessibleName, type AccessibleName } from '../../internal/accessibleName.js'
|
|
14
|
-
import { cn } from '
|
|
14
|
+
import { cn } from 'cn'
|
|
15
15
|
import { joinIds } from '../../internal/ids.js'
|
|
16
16
|
import {
|
|
17
17
|
isItemOpen,
|
|
@@ -330,6 +330,8 @@ function Indicator({
|
|
|
330
330
|
attributes: true,
|
|
331
331
|
attributeFilter: ['aria-pressed', 'class', 'style', 'hidden', 'dir']
|
|
332
332
|
})
|
|
333
|
+
for (let parent = root.parentElement; parent; parent = parent.parentElement)
|
|
334
|
+
changes.observe(parent, { attributes: true, attributeFilter: ['dir'] })
|
|
333
335
|
observe()
|
|
334
336
|
measure()
|
|
335
337
|
view.addEventListener('resize', schedule)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { useRef, type ComponentProps } from 'react'
|
|
3
|
-
import { cn } from '
|
|
3
|
+
import { cn } from 'cn'
|
|
4
4
|
import { joinIds } from '../../internal/ids.js'
|
|
5
5
|
import { requireAccessibleName, type AccessibleName } from '../../internal/accessibleName.js'
|
|
6
6
|
import { useComposedRefs } from '../../react/useComposedRefs.js'
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
} from 'react'
|
|
13
13
|
import { createPortal } from 'react-dom'
|
|
14
14
|
import { Button, type ButtonProps, type ButtonRenderProps } from '../Button/Button.js'
|
|
15
|
-
import { cn } from '
|
|
15
|
+
import { cn } from 'cn'
|
|
16
16
|
import { joinIds } from '../../internal/ids.js'
|
|
17
17
|
import { composeAction } from '../../internal/events.js'
|
|
18
18
|
import type { PopoverSide, PopoverAlign } from '../../internal/popover.js'
|
|
@@ -112,6 +112,7 @@ export type TooltipContentProps = Omit<
|
|
|
112
112
|
sideOffset?: number
|
|
113
113
|
collisionPadding?: number
|
|
114
114
|
motion?: 'inherit' | 'off'
|
|
115
|
+
'data-slot'?: string
|
|
115
116
|
}
|
|
116
117
|
export function TooltipTrigger({
|
|
117
118
|
ref,
|
|
@@ -189,7 +190,7 @@ export function TooltipContent({
|
|
|
189
190
|
role="tooltip"
|
|
190
191
|
popover="manual"
|
|
191
192
|
tabIndex={undefined}
|
|
192
|
-
data-slot=
|
|
193
|
+
data-slot={joinIds('tooltip-content', props['data-slot'])}
|
|
193
194
|
data-state={tip.open ? 'open' : 'closed'}
|
|
194
195
|
data-side={side}
|
|
195
196
|
data-align={align}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { cva } from 'class-variance-authority'
|
|
2
|
+
import { focusRingClass } from './focusStyles.js'
|
|
2
3
|
|
|
3
4
|
// Palette and readable ink are shared by actions, text links and inline feedback. Ink is
|
|
4
5
|
// mixed toward the scope foreground so pale warning/accent fills stay readable
|
|
@@ -54,7 +55,8 @@ export const actionVariants = cva(
|
|
|
54
55
|
'not-disabled:not-aria-busy:motion-safe:active:scale-[var(--rad-button-press-scale,var(--rad-motion-press-scale,0.97))] not-disabled:not-aria-busy:motion-safe:active:translate-y-[var(--rad-button-press-shift,var(--rad-motion-press-shift-y,0px))] not-disabled:not-aria-busy:motion-safe:active:translate-x-[var(--rad-button-press-shift-x,var(--rad-motion-press-shift-x,0px))]',
|
|
55
56
|
'not-disabled:not-aria-busy:active:rounded-(--_btn-radius-pressed) not-disabled:not-aria-busy:active:[corner-shape:var(--rad-button-corner-shape-pressed,var(--rad-control-action-corner-shape-pressed,var(--_btn-corner)))]',
|
|
56
57
|
'not-disabled:not-aria-busy:active:[--_btn-highlight:0] not-disabled:not-aria-busy:active:[--_btn-sheen:0] not-disabled:not-aria-busy:active:shadow-[var(--rad-button-shadow-pressed,var(--_btn-shadow-pressed))]',
|
|
57
|
-
|
|
58
|
+
focusRingClass,
|
|
59
|
+
'focus-visible:[--_rad-focus-color:var(--rad-button-focus-color)] focus-visible:[--_rad-focus-width:var(--rad-button-focus-width)] focus-visible:[--_rad-focus-offset:var(--rad-button-focus-offset)] focus-visible:[--_rad-focus-style:var(--rad-button-focus-style)]',
|
|
58
60
|
'in-[[data-slot~=field][data-disabled]]:[--_rad-disabled-opacity:1]',
|
|
59
61
|
'disabled:cursor-not-allowed disabled:opacity-[var(--_rad-disabled-opacity,var(--rad-button-disabled-opacity,var(--rad-state-disabled-opacity,0.5)))]',
|
|
60
62
|
'aria-busy:cursor-progress',
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Every focus ring reads one chain: the family's slot, then the shared focus tokens, then the
|
|
2
|
+
// baseline. A family with its own focus tokens fills the private `--_rad-focus-*` slots under
|
|
3
|
+
// the same state that draws its ring, so the slots never leak into nested hosts.
|
|
4
|
+
// An unset family token leaves its slot empty and the shared token takes over.
|
|
5
|
+
|
|
6
|
+
/** The ring for a host that takes keyboard focus itself. */
|
|
7
|
+
export const focusRingClass =
|
|
8
|
+
'focus-visible:outline-[color:var(--_rad-focus-color,var(--rad-color-focus,oklch(0.55_0.13_255)))] focus-visible:outline-[length:var(--_rad-focus-width,var(--rad-focus-width,2px))] focus-visible:outline-offset-[var(--_rad-focus-offset,var(--rad-focus-offset,2px))] focus-visible:[outline-style:var(--_rad-focus-style,var(--rad-focus-style,solid))] forced-colors:focus-visible:outline-[Highlight]'
|
|
9
|
+
|
|
10
|
+
/** A scroll box draws its ring inside its edge, where overflow cannot clip it. */
|
|
11
|
+
export const focusRingInsetClass =
|
|
12
|
+
'focus-visible:[--_rad-focus-offset:calc(0px_-_var(--_rad-focus-width,var(--rad-focus-width,2px)))]'
|
|
13
|
+
|
|
14
|
+
/** The ring for a visible stand-in that follows a focused `peer` input. */
|
|
15
|
+
export const peerFocusRingClass =
|
|
16
|
+
'peer-focus-visible:outline-[color:var(--_rad-focus-color,var(--rad-color-focus,oklch(0.55_0.13_255)))] peer-focus-visible:outline-[length:var(--_rad-focus-width,var(--rad-focus-width,2px))] peer-focus-visible:outline-offset-[var(--_rad-focus-offset,var(--rad-focus-offset,2px))] peer-focus-visible:[outline-style:var(--_rad-focus-style,var(--rad-focus-style,solid))] forced-colors:peer-focus-visible:outline-[Highlight]'
|
|
17
|
+
|
|
18
|
+
/** The ring for a field shell around a focused child control. */
|
|
19
|
+
export const focusWithinRingClass =
|
|
20
|
+
'focus-within:outline-[color:var(--_rad-focus-color,var(--rad-color-focus,oklch(0.55_0.13_255)))] focus-within:outline-[length:var(--_rad-focus-width,var(--rad-focus-width,2px))] focus-within:outline-offset-[var(--_rad-focus-offset,var(--rad-focus-offset,2px))] focus-within:[outline-style:var(--_rad-focus-style,var(--rad-focus-style,solid))] forced-colors:focus-within:outline-[Highlight]'
|
|
21
|
+
|
|
22
|
+
/** The ring for a field shell whose direct input child has keyboard focus. */
|
|
23
|
+
export const childFocusRingClass =
|
|
24
|
+
'has-[>input:focus-visible]:outline-[color:var(--_rad-focus-color,var(--rad-color-focus,oklch(0.55_0.13_255)))] has-[>input:focus-visible]:outline-[length:var(--_rad-focus-width,var(--rad-focus-width,2px))] has-[>input:focus-visible]:outline-offset-[var(--_rad-focus-offset,var(--rad-focus-offset,2px))] has-[>input:focus-visible]:[outline-style:var(--_rad-focus-style,var(--rad-focus-style,solid))] forced-colors:has-[>input:focus-visible]:outline-[Highlight]'
|
|
25
|
+
|
|
26
|
+
/** The ring for a slot that shows where a hidden input's caret is. */
|
|
27
|
+
export const activeRingClass =
|
|
28
|
+
'data-active:outline-[color:var(--_rad-focus-color,var(--rad-color-focus,oklch(0.55_0.13_255)))] data-active:outline-[length:var(--_rad-focus-width,var(--rad-focus-width,2px))] data-active:outline-offset-[var(--_rad-focus-offset,var(--rad-focus-offset,2px))] data-active:[outline-style:var(--_rad-focus-style,var(--rad-focus-style,solid))] forced-colors:data-active:outline-[Highlight]'
|
package/src/css.d.ts
ADDED
package/src/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { Link, type LinkProps } from '../components/Link/Link.js'
|
|
3
|
-
import { cn } from '
|
|
3
|
+
import { cn } from 'cn'
|
|
4
4
|
import { usePressHost } from './host.js'
|
|
5
5
|
import { callerOwnsPress, springPressClass, offPressClass } from './pressPolicy.js'
|
|
6
6
|
export type MotionLinkProps = LinkProps & {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
|
-
import { useLayoutEffect, useRef, type RefObject } from 'react'
|
|
3
|
+
import { useLayoutEffect, useRef, useState, type RefObject } from 'react'
|
|
4
4
|
import { positionSelect } from '../internal/select.js'
|
|
5
5
|
|
|
6
6
|
/** Local top-layer popup: preserve theme/modal ancestry and place before its first paint. */
|
|
@@ -12,15 +12,47 @@ export function useComboboxPopup(
|
|
|
12
12
|
sideOffset: number,
|
|
13
13
|
collisionPadding: number
|
|
14
14
|
) {
|
|
15
|
-
const latest = useRef(dismiss)
|
|
15
|
+
const latest = useRef({ dismiss, open })
|
|
16
16
|
const reposition = useRef<() => void>(() => {})
|
|
17
|
+
const [generation, setGeneration] = useState(0)
|
|
17
18
|
useLayoutEffect(() => {
|
|
18
|
-
latest.current = dismiss
|
|
19
|
+
latest.current = { dismiss, open }
|
|
19
20
|
})
|
|
21
|
+
// A manual popup stays in the top layer after an ancestor dialog or popover closes.
|
|
20
22
|
useLayoutEffect(() => {
|
|
21
23
|
const node = nodeRef.current
|
|
22
24
|
if (!node || !input) return
|
|
23
|
-
|
|
25
|
+
const ancestors: HTMLElement[] = []
|
|
26
|
+
for (let parent = input.parentElement; parent; parent = parent.parentElement) {
|
|
27
|
+
if (parent.matches('dialog, [popover]')) ancestors.push(parent)
|
|
28
|
+
}
|
|
29
|
+
const reconcile = () => {
|
|
30
|
+
if (!latest.current.open) return
|
|
31
|
+
const visible = input.checkVisibility()
|
|
32
|
+
if (!visible && node.matches(':popover-open')) {
|
|
33
|
+
latest.current.dismiss()
|
|
34
|
+
node.hidePopover()
|
|
35
|
+
setGeneration(value => value + 1)
|
|
36
|
+
} else if (visible && !node.matches(':popover-open')) setGeneration(value => value + 1)
|
|
37
|
+
}
|
|
38
|
+
const toggle = (event: Event) => {
|
|
39
|
+
if (event.target === event.currentTarget) reconcile()
|
|
40
|
+
}
|
|
41
|
+
const view = input.ownerDocument.defaultView!
|
|
42
|
+
const observer = new view.MutationObserver(reconcile)
|
|
43
|
+
for (const ancestor of ancestors) {
|
|
44
|
+
observer.observe(ancestor, { attributes: true, attributeFilter: ['open', 'data-state'] })
|
|
45
|
+
ancestor.addEventListener('toggle', toggle)
|
|
46
|
+
}
|
|
47
|
+
return () => {
|
|
48
|
+
observer.disconnect()
|
|
49
|
+
for (const ancestor of ancestors) ancestor.removeEventListener('toggle', toggle)
|
|
50
|
+
}
|
|
51
|
+
}, [nodeRef, input])
|
|
52
|
+
useLayoutEffect(() => {
|
|
53
|
+
const node = nodeRef.current
|
|
54
|
+
if (!node || !input) return
|
|
55
|
+
if (!open || !input.checkVisibility()) {
|
|
24
56
|
if (node.matches(':popover-open')) node.hidePopover()
|
|
25
57
|
return
|
|
26
58
|
}
|
|
@@ -103,7 +135,7 @@ export function useComboboxPopup(
|
|
|
103
135
|
!node.contains(target) &&
|
|
104
136
|
!input.parentElement?.contains(target)
|
|
105
137
|
)
|
|
106
|
-
latest.current()
|
|
138
|
+
latest.current.dismiss()
|
|
107
139
|
}
|
|
108
140
|
const observer = new win.ResizeObserver(schedule)
|
|
109
141
|
const mutations = new win.MutationObserver(schedule)
|
|
@@ -129,7 +161,7 @@ export function useComboboxPopup(
|
|
|
129
161
|
win.visualViewport?.removeEventListener('scroll', schedule)
|
|
130
162
|
if (node.matches(':popover-open')) node.hidePopover()
|
|
131
163
|
}
|
|
132
|
-
}, [nodeRef, input, open, sideOffset, collisionPadding])
|
|
164
|
+
}, [nodeRef, input, open, sideOffset, collisionPadding, generation])
|
|
133
165
|
// Selected tags can move an unchanged-size input without a resize event.
|
|
134
166
|
useLayoutEffect(() => {
|
|
135
167
|
reposition.current()
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import {
|
|
4
4
|
createContext,
|
|
5
5
|
useLayoutEffect,
|
|
6
|
+
useRef,
|
|
6
7
|
type KeyboardEvent,
|
|
7
8
|
type FocusEvent,
|
|
8
9
|
type RefObject
|
|
@@ -35,19 +36,36 @@ export function useRovingFocus<Node extends HTMLElement>({
|
|
|
35
36
|
deferTo,
|
|
36
37
|
includeAriaDisabled = false
|
|
37
38
|
}: Options<Node>) {
|
|
39
|
+
const latest = useRef({
|
|
40
|
+
selector,
|
|
41
|
+
scope,
|
|
42
|
+
preferred,
|
|
43
|
+
orientation,
|
|
44
|
+
loop,
|
|
45
|
+
active,
|
|
46
|
+
deferTo,
|
|
47
|
+
includeAriaDisabled
|
|
48
|
+
})
|
|
49
|
+
const appliedTo = useRef<Node | null>(null)
|
|
50
|
+
const settleRef = useRef<(node: Node) => void>(() => {})
|
|
51
|
+
const binding = useRef<{ node: Node; cleanup: () => void } | null>(null)
|
|
38
52
|
const ownsFocus = (node: Node) => {
|
|
53
|
+
const { active, deferTo } = latest.current
|
|
39
54
|
if (!active) return false
|
|
40
55
|
const parent = deferTo ? node.parentElement?.closest(deferTo) : null
|
|
41
56
|
const surface = node.closest('[popover], dialog')
|
|
42
57
|
// React context crosses portals; native focus ownership stops at a new surface.
|
|
43
58
|
return !parent || !!(surface && parent.contains(surface))
|
|
44
59
|
}
|
|
45
|
-
const items = (node: Node) =>
|
|
46
|
-
|
|
60
|
+
const items = (node: Node) => {
|
|
61
|
+
const { selector, scope } = latest.current
|
|
62
|
+
return Array.from(node.querySelectorAll<HTMLElement>(selector)).filter(item => {
|
|
47
63
|
const surface = item.closest('[popover], dialog')
|
|
48
64
|
return item.closest(scope) === node && (!surface || !node.contains(surface))
|
|
49
65
|
})
|
|
66
|
+
}
|
|
50
67
|
const enabled = (node: Node) => {
|
|
68
|
+
const { includeAriaDisabled } = latest.current
|
|
51
69
|
const view = node.ownerDocument.defaultView!
|
|
52
70
|
return items(node).filter(
|
|
53
71
|
item =>
|
|
@@ -59,6 +77,7 @@ export function useRovingFocus<Node extends HTMLElement>({
|
|
|
59
77
|
)
|
|
60
78
|
}
|
|
61
79
|
const sync = (node: Node, preferFocus = true) => {
|
|
80
|
+
const { preferred } = latest.current
|
|
62
81
|
const all = items(node),
|
|
63
82
|
available = enabled(node)
|
|
64
83
|
const focused = node.ownerDocument.activeElement
|
|
@@ -78,13 +97,47 @@ export function useRovingFocus<Node extends HTMLElement>({
|
|
|
78
97
|
if (item.tabIndex !== index) item.tabIndex = index
|
|
79
98
|
}
|
|
80
99
|
}
|
|
100
|
+
useLayoutEffect(() => {
|
|
101
|
+
latest.current = {
|
|
102
|
+
selector,
|
|
103
|
+
scope,
|
|
104
|
+
preferred,
|
|
105
|
+
orientation,
|
|
106
|
+
loop,
|
|
107
|
+
active,
|
|
108
|
+
deferTo,
|
|
109
|
+
includeAriaDisabled
|
|
110
|
+
}
|
|
111
|
+
settleRef.current = (node: Node) => {
|
|
112
|
+
if (!ownsFocus(node)) {
|
|
113
|
+
if (appliedTo.current !== node) return
|
|
114
|
+
for (const item of items(node)) if (item.tabIndex !== 0) item.tabIndex = 0
|
|
115
|
+
appliedTo.current = null
|
|
116
|
+
return
|
|
117
|
+
}
|
|
118
|
+
sync(node)
|
|
119
|
+
appliedTo.current = node
|
|
120
|
+
}
|
|
121
|
+
})
|
|
122
|
+
useLayoutEffect(() => {
|
|
123
|
+
const node = host.current
|
|
124
|
+
if (node) settleRef.current(node)
|
|
125
|
+
}, [host, selector, scope, preferred, active, deferTo, includeAriaDisabled])
|
|
81
126
|
useLayoutEffect(() => {
|
|
82
127
|
const node = host.current
|
|
83
|
-
if (!node ||
|
|
128
|
+
if (!node || binding.current?.node === node) {
|
|
129
|
+
if (!node && binding.current) {
|
|
130
|
+
binding.current.cleanup()
|
|
131
|
+
binding.current = null
|
|
132
|
+
}
|
|
133
|
+
return
|
|
134
|
+
}
|
|
135
|
+
binding.current?.cleanup()
|
|
136
|
+
binding.current = null
|
|
84
137
|
const view = node.ownerDocument.defaultView!
|
|
85
|
-
const reconcile = () =>
|
|
86
|
-
reconcile()
|
|
138
|
+
const reconcile = () => settleRef.current(node)
|
|
87
139
|
const observer = new view.MutationObserver(records => {
|
|
140
|
+
const selector = latest.current.selector
|
|
88
141
|
if (
|
|
89
142
|
records.some(
|
|
90
143
|
record =>
|
|
@@ -119,11 +172,22 @@ export function useRovingFocus<Node extends HTMLElement>({
|
|
|
119
172
|
})
|
|
120
173
|
const resize = new view.ResizeObserver(reconcile)
|
|
121
174
|
resize.observe(node)
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
175
|
+
binding.current = {
|
|
176
|
+
node,
|
|
177
|
+
cleanup: () => {
|
|
178
|
+
observer.disconnect()
|
|
179
|
+
resize.disconnect()
|
|
180
|
+
}
|
|
125
181
|
}
|
|
182
|
+
settleRef.current(node)
|
|
126
183
|
})
|
|
184
|
+
useLayoutEffect(
|
|
185
|
+
() => () => {
|
|
186
|
+
binding.current?.cleanup()
|
|
187
|
+
binding.current = null
|
|
188
|
+
},
|
|
189
|
+
[]
|
|
190
|
+
)
|
|
127
191
|
return {
|
|
128
192
|
items: enabled,
|
|
129
193
|
onFocus(event: FocusEvent<Node>) {
|
|
@@ -149,6 +213,7 @@ export function useRovingFocus<Node extends HTMLElement>({
|
|
|
149
213
|
event.nativeEvent.isComposing
|
|
150
214
|
)
|
|
151
215
|
return
|
|
216
|
+
const { selector, orientation, loop } = latest.current
|
|
152
217
|
const node = event.currentTarget,
|
|
153
218
|
available = enabled(node),
|
|
154
219
|
current = (event.target as Element).closest(selector),
|
|
@@ -27,36 +27,51 @@ export function useToastTimer(
|
|
|
27
27
|
() => latest.current()
|
|
28
28
|
)
|
|
29
29
|
let hovering = node.matches(':hover')
|
|
30
|
+
let touching = false
|
|
30
31
|
const sync = () => {
|
|
31
|
-
const paused = hovering || node.contains(doc.activeElement) || doc.hidden
|
|
32
|
-
node.
|
|
32
|
+
const paused = hovering || touching || node.contains(doc.activeElement) || doc.hidden
|
|
33
|
+
node.toggleAttribute('data-paused', paused)
|
|
33
34
|
if (paused) timer.pause()
|
|
34
35
|
else timer.resume()
|
|
35
36
|
}
|
|
36
37
|
const enter = (event: PointerEvent) => {
|
|
37
|
-
if (event.pointerType
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
38
|
+
if (event.pointerType === 'touch') return
|
|
39
|
+
hovering = true
|
|
40
|
+
sync()
|
|
41
41
|
}
|
|
42
42
|
const leave = (event: PointerEvent) => {
|
|
43
|
-
if (event.pointerType
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
if (event.pointerType === 'touch') return
|
|
44
|
+
hovering = false
|
|
45
|
+
sync()
|
|
46
|
+
}
|
|
47
|
+
const press = (event: PointerEvent) => {
|
|
48
|
+
if (event.pointerType !== 'touch') return
|
|
49
|
+
touching = true
|
|
50
|
+
sync()
|
|
51
|
+
}
|
|
52
|
+
const release = (event: PointerEvent) => {
|
|
53
|
+
if (event.pointerType !== 'touch' || !touching) return
|
|
54
|
+
touching = false
|
|
55
|
+
sync()
|
|
47
56
|
}
|
|
48
57
|
node.addEventListener('pointerenter', enter)
|
|
49
58
|
node.addEventListener('pointerleave', leave)
|
|
59
|
+
node.addEventListener('pointerdown', press)
|
|
50
60
|
node.addEventListener('focusin', sync)
|
|
51
61
|
node.addEventListener('focusout', sync)
|
|
62
|
+
doc.addEventListener('pointerup', release)
|
|
63
|
+
doc.addEventListener('pointercancel', release)
|
|
52
64
|
doc.addEventListener('visibilitychange', sync)
|
|
53
65
|
sync()
|
|
54
66
|
return () => {
|
|
55
67
|
timer.destroy()
|
|
56
68
|
node.removeEventListener('pointerenter', enter)
|
|
57
69
|
node.removeEventListener('pointerleave', leave)
|
|
70
|
+
node.removeEventListener('pointerdown', press)
|
|
58
71
|
node.removeEventListener('focusin', sync)
|
|
59
72
|
node.removeEventListener('focusout', sync)
|
|
73
|
+
doc.removeEventListener('pointerup', release)
|
|
74
|
+
doc.removeEventListener('pointercancel', release)
|
|
60
75
|
doc.removeEventListener('visibilitychange', sync)
|
|
61
76
|
delete node.dataset.paused
|
|
62
77
|
}
|
package/src/styles.d.ts
CHANGED
package/src/themes/baseline.css
CHANGED