diff --git a/categories/blob/react/src/components/FileSelectBox/index.tsx b/categories/blob/react/src/components/FileSelectBox/index.tsx index 5f62277..54317c8 100644 --- a/categories/blob/react/src/components/FileSelectBox/index.tsx +++ b/categories/blob/react/src/components/FileSelectBox/index.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import { delegateTriggerEvent, useClientSide } from '@modal-sh/react-utils'; +import { useClientSide, useFallbackId } from '@modal-sh/react-utils'; import clsx from 'clsx'; export interface CommonPreviewProps = Partial> { @@ -64,8 +64,7 @@ export const FileSelectBox = React.forwardRef(null); const ref = forwardedRef ?? defaultRef; const labelId = React.useId(); - const defaultId = React.useId(); - const id = idProp ?? defaultId; + const id = useFallbackId(idProp); const doSetFileList: React.ChangeEventHandler = (e) => { if (enhancedProp) { diff --git a/categories/choice/react/package.json b/categories/choice/react/package.json index d261e0d..094eb4b 100644 --- a/categories/choice/react/package.json +++ b/categories/choice/react/package.json @@ -62,6 +62,7 @@ }, "dependencies": { "@tesseract-design/web-base": "workspace:*", + "@modal-sh/react-utils": "workspace:*", "clsx": "^1.2.1", "tailwindcss": "3.3.2" }, diff --git a/categories/choice/react/src/components/ComboBox/index.tsx b/categories/choice/react/src/components/ComboBox/index.tsx index 2ae1cfc..770e7dc 100644 --- a/categories/choice/react/src/components/ComboBox/index.tsx +++ b/categories/choice/react/src/components/ComboBox/index.tsx @@ -1,5 +1,6 @@ import * as React from 'react'; import { TextControl } from '@tesseract-design/web-base'; +import { useFallbackId } from '@modal-sh/react-utils'; import clsx from 'clsx'; /** @@ -85,8 +86,7 @@ export const ComboBox = React.forwardRef( ) => { const labelId = React.useId(); const datalistId = React.useId(); - const defaultId = React.useId(); - const id = idProp ?? defaultId; + const id = useFallbackId(idProp); let resultInputMode = inputMode as React.HTMLProps['inputMode']; if (type === 'text' && resultInputMode === 'search') { diff --git a/categories/choice/react/src/components/DropdownSelect/index.tsx b/categories/choice/react/src/components/DropdownSelect/index.tsx index cc8a8a7..f91e01b 100644 --- a/categories/choice/react/src/components/DropdownSelect/index.tsx +++ b/categories/choice/react/src/components/DropdownSelect/index.tsx @@ -2,6 +2,7 @@ import * as React from 'react'; import { TextControl } from '@tesseract-design/web-base'; import plugin from 'tailwindcss/plugin'; import clsx from 'clsx'; +import { useFallbackId } from '@modal-sh/react-utils'; /** * Derived HTML element of the {@link DropdownSelect} component. @@ -85,8 +86,7 @@ export const DropdownSelect = React.forwardRef { const labelId = React.useId(); - const defaultId = React.useId(); - const id = idProp ?? defaultId; + const id = useFallbackId(idProp); return (
{ const labelId = React.useId(); - const defaultId = React.useId(); - const id = idProp ?? defaultId; + const id = useFallbackId(idProp); return (
{ - const defaultId = React.useId(); - const id = idProp ?? defaultId; + const id = useFallbackId(idProp); + return ( <> { - const defaultId = React.useId(); - const id = idProp ?? defaultId; + const id = useFallbackId(idProp); + return (
{ const labelId = React.useId(); - const defaultId = React.useId(); - const id = idProp ?? defaultId; + const id = useFallbackId(idProp); const pattern = ( Array.isArray(domains) && domains.length > 0 diff --git a/categories/formatted/react/src/components/PatternTextInput/index.tsx b/categories/formatted/react/src/components/PatternTextInput/index.tsx index 17edcf5..43e0702 100644 --- a/categories/formatted/react/src/components/PatternTextInput/index.tsx +++ b/categories/formatted/react/src/components/PatternTextInput/index.tsx @@ -1,6 +1,7 @@ import * as React from 'react'; import { TextControl } from '@tesseract-design/web-base'; import clsx from 'clsx'; +import {useFallbackId} from '@modal-sh/react-utils'; export type PatternTextInputDerivedElement = HTMLInputElement; @@ -80,8 +81,7 @@ export const PatternTextInput = React.forwardRef< forwardedRef, ) => { const labelId = React.useId(); - const defaultId = React.useId(); - const id = idProp ?? defaultId; + const id = useFallbackId(idProp); let resultInputMode = inputMode as React.HTMLProps['inputMode']; if (type === 'text' && resultInputMode === 'search') { diff --git a/categories/formatted/react/src/components/PhoneNumberInput/index.tsx b/categories/formatted/react/src/components/PhoneNumberInput/index.tsx index 964f39f..4d5fe5a 100644 --- a/categories/formatted/react/src/components/PhoneNumberInput/index.tsx +++ b/categories/formatted/react/src/components/PhoneNumberInput/index.tsx @@ -1,6 +1,6 @@ import * as React from 'react'; import { TextControl } from '@tesseract-design/web-base'; -import { useClientSide, useProxyInput } from '@modal-sh/react-utils'; +import {useClientSide, useFallbackId, useProxyInput} from '@modal-sh/react-utils'; import PhoneInput, { Country, Value } from 'react-phone-number-input/input'; import clsx from 'clsx'; @@ -83,8 +83,7 @@ export const PhoneNumberInput = React.forwardRef< value?.toString() ?? defaultValue?.toString() ?? '', ); const labelId = React.useId(); - const defaultId = React.useId(); - const id = idProp ?? defaultId; + const id = useFallbackId(idProp); const { defaultRef, handleChange: handlePhoneInputChange, diff --git a/categories/formatted/react/src/components/UrlInput/index.tsx b/categories/formatted/react/src/components/UrlInput/index.tsx index a732edf..4627e66 100644 --- a/categories/formatted/react/src/components/UrlInput/index.tsx +++ b/categories/formatted/react/src/components/UrlInput/index.tsx @@ -1,6 +1,7 @@ import * as React from 'react'; import { TextControl } from '@tesseract-design/web-base'; import clsx from 'clsx'; +import {useFallbackId} from '@modal-sh/react-utils'; export type UrlInputDerivedElement = HTMLInputElement; @@ -60,8 +61,7 @@ export const UrlInput = React.forwardRef( forwardedRef, ) => { const labelId = React.useId(); - const defaultId = React.useId(); - const id = idProp ?? defaultId; + const id = useFallbackId(idProp); return (
{ const labelId = React.useId(); - const defaultId = React.useId(); - const id = idProp ?? defaultId; + const id = useFallbackId(idProp); return (
{ const labelId = React.useId(); - const defaultId = React.useId(); - const id = idProp ?? defaultId; + const id = useFallbackId(idProp); let resultInputMode = inputMode as React.HTMLProps['inputMode']; if (type === 'text' && resultInputMode === 'search') { diff --git a/categories/multichoice/react/src/components/MenuMultiSelect/index.tsx b/categories/multichoice/react/src/components/MenuMultiSelect/index.tsx index 80bb0f3..4ce694b 100644 --- a/categories/multichoice/react/src/components/MenuMultiSelect/index.tsx +++ b/categories/multichoice/react/src/components/MenuMultiSelect/index.tsx @@ -2,6 +2,7 @@ import * as React from 'react'; import { TextControl } from '@tesseract-design/web-base'; import clsx from 'clsx'; import plugin from 'tailwindcss/plugin'; +import {useFallbackId} from '@modal-sh/react-utils'; export type MenuMultiSelectDerivedElement = HTMLSelectElement; @@ -92,8 +93,7 @@ export const MenuMultiSelect = React.forwardRef< forwardedRef, ) => { const labelId = React.useId(); - const defaultId = React.useId(); - const id = idProp ?? defaultId; + const id = useFallbackId(idProp); return (
( }); const ref = forwardedRef ?? defaultRef; const labelId = React.useId(); - const defaultId = React.useId(); - const id = idProp ?? defaultId; + const id = useFallbackId(idProp); const handleFocus: React.FocusEventHandler = (e) => { if (!clientSide) { diff --git a/categories/multichoice/react/src/components/ToggleButton/index.tsx b/categories/multichoice/react/src/components/ToggleButton/index.tsx index 3c29eb8..b96b71a 100644 --- a/categories/multichoice/react/src/components/ToggleButton/index.tsx +++ b/categories/multichoice/react/src/components/ToggleButton/index.tsx @@ -2,6 +2,7 @@ import * as React from 'react'; import clsx from 'clsx'; import { Button } from '@tesseract-design/web-base'; import plugin from 'tailwindcss/plugin'; +import {useFallbackId} from '@modal-sh/react-utils'; export type ToggleButtonDerivedElement = HTMLInputElement; @@ -52,8 +53,7 @@ export const ToggleButton = React.forwardRef { const defaultRef = React.useRef(null); const ref = forwardedRef ?? defaultRef; - const defaultId = React.useId(); - const id = idProp ?? defaultId; + const id = useFallbackId(idProp); React.useEffect(() => { if (typeof ref === 'function') { diff --git a/categories/multichoice/react/src/components/ToggleSwitch/index.tsx b/categories/multichoice/react/src/components/ToggleSwitch/index.tsx index 4ca6125..1396b30 100644 --- a/categories/multichoice/react/src/components/ToggleSwitch/index.tsx +++ b/categories/multichoice/react/src/components/ToggleSwitch/index.tsx @@ -1,6 +1,7 @@ import * as React from 'react'; import clsx from 'clsx'; import plugin from 'tailwindcss/plugin'; +import {useFallbackId} from '@modal-sh/react-utils'; export type ToggleSwitchDerivedElement = HTMLInputElement; @@ -149,8 +150,7 @@ export const ToggleSwitch = React.forwardRef { const defaultRef = React.useRef(null); const ref = forwardedRef ?? defaultRef; - const defaultId = React.useId(); - const id = idProp ?? defaultId; + const id = useFallbackId(idProp); React.useEffect(() => { if (typeof ref === 'function') { diff --git a/categories/multichoice/react/src/components/ToggleTickBox/index.tsx b/categories/multichoice/react/src/components/ToggleTickBox/index.tsx index c5325c9..6dfacaa 100644 --- a/categories/multichoice/react/src/components/ToggleTickBox/index.tsx +++ b/categories/multichoice/react/src/components/ToggleTickBox/index.tsx @@ -1,6 +1,7 @@ import * as React from 'react'; import clsx from 'clsx'; import plugin from 'tailwindcss/plugin'; +import {useFallbackId} from '@modal-sh/react-utils'; export type ToggleTickBoxDerivedElement = HTMLInputElement; @@ -44,8 +45,7 @@ export const ToggleTickBox = React.forwardRef { const defaultRef = React.useRef(null); const ref = forwardedRef ?? defaultRef; - const defaultId = React.useId(); - const id = idProp ?? defaultId; + const id = useFallbackId(idProp); React.useEffect(() => { if (typeof ref === 'function') { diff --git a/categories/number/react/package.json b/categories/number/react/package.json index 8c0c849..bfa0047 100644 --- a/categories/number/react/package.json +++ b/categories/number/react/package.json @@ -62,6 +62,7 @@ }, "dependencies": { "@tesseract-design/web-base": "workspace:*", + "@modal-sh/react-utils": "workspace:*", "clsx": "^1.2.1", "tailwindcss": "3.3.3" }, diff --git a/categories/number/react/src/components/NumberSpinner/index.tsx b/categories/number/react/src/components/NumberSpinner/index.tsx index 5f87cf6..6d529d1 100644 --- a/categories/number/react/src/components/NumberSpinner/index.tsx +++ b/categories/number/react/src/components/NumberSpinner/index.tsx @@ -2,6 +2,7 @@ import * as React from 'react'; import { TextControl } from '@tesseract-design/web-base'; import clsx from 'clsx'; import plugin from 'tailwindcss/plugin'; +import {useFallbackId} from '@modal-sh/react-utils'; export type NumberSpinnerDerivedElement = HTMLInputElement; @@ -81,8 +82,7 @@ export const NumberSpinner = React.forwardRef { const labelId = React.useId(); - const defaultId = React.useId(); - const id = idProp ?? defaultId; + const id = useFallbackId(idProp); return (
{ const labelId = React.useId(); - const defaultId = React.useId(); - const id = idProp ?? defaultId; + const id = useFallbackId(idProp); return (
{ const labelId = React.useId(); - const defaultId = React.useId(); - const id = idProp ?? defaultId; + const id = useFallbackId(idProp); const [hh, mm, ss = 0] = step.split(':').map((s: string) => parseInt(s, 10)) as number[]; const stepValue = ss + (mm * 60) + (hh * 3600); diff --git a/packages/react-utils/src/event.ts b/packages/react-utils/src/event.ts index 3d5bb7f..a818c00 100644 --- a/packages/react-utils/src/event.ts +++ b/packages/react-utils/src/event.ts @@ -13,7 +13,9 @@ export const delegateTriggerEvent = ( 'TEXTAREA': window.HTMLTextAreaElement, } as const; - const { [target.tagName as keyof typeof TAG_NAME_ELEMENT_CONSTRUCTOR]: elementCtor } = TAG_NAME_ELEMENT_CONSTRUCTOR; + const { + [target.tagName as keyof typeof TAG_NAME_ELEMENT_CONSTRUCTOR]: elementCtor, + } = TAG_NAME_ELEMENT_CONSTRUCTOR; if (!elementCtor) { return; @@ -31,6 +33,5 @@ export const delegateTriggerEvent = ( const simulatedEvent = new Event(eventName, {bubbles: true}); target.dispatchEvent(simulatedEvent); } - return; } }; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f80029d..2610a2d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -145,6 +145,9 @@ importers: categories/choice/react: dependencies: + '@modal-sh/react-utils': + specifier: workspace:* + version: link:../../../packages/react-utils '@tesseract-design/web-base': specifier: workspace:* version: link:../../../base @@ -584,6 +587,9 @@ importers: categories/number/react: dependencies: + '@modal-sh/react-utils': + specifier: workspace:* + version: link:../../../packages/react-utils '@tesseract-design/web-base': specifier: workspace:* version: link:../../../base @@ -648,6 +654,9 @@ importers: categories/temporal/react: dependencies: + '@modal-sh/react-utils': + specifier: workspace:* + version: link:../../../packages/react-utils '@tesseract-design/web-base': specifier: workspace:* version: link:../../../base