An open source design system that's fully customizable and agent ready
TypeScript
fix(forms): rename tooltip→labelTooltip, startIcon→labelIcon for consistency (#375)
Cindy Zhang76ac3be603f8
diff --git a/apps/storybook/stories/CheckboxInput.stories.tsx b/apps/storybook/stories/CheckboxInput.stories.tsxindex 010294ddf4..d1ef00f113 100644--- a/apps/storybook/stories/CheckboxInput.stories.tsx+++ b/apps/storybook/stories/CheckboxInput.stories.tsx@@ -340,21 +340,21 @@ export const StartIconVariations: Story = {description="Receive updates via email"value={value1}onChange={setValue1}- startIcon={EnvelopeIcon}+ labelIcon={EnvelopeIcon}/><XDSCheckboxInputlabel="Push notifications"description="Get instant alerts on your device"value={value2}onChange={setValue2}- startIcon={BellIcon}+ labelIcon={BellIcon}/><XDSCheckboxInputlabel="Two-factor authentication"description="Add an extra layer of security"value={value3}onChange={setValue3}- startIcon={ShieldCheckIcon}+ labelIcon={ShieldCheckIcon}isDisabled/></div>diff --git a/packages/core/src/CheckboxInput/XDSCheckboxInput.tsx b/packages/core/src/CheckboxInput/XDSCheckboxInput.tsxindex 1056bfdb4b..0044b39f17 100644--- a/packages/core/src/CheckboxInput/XDSCheckboxInput.tsx+++ b/packages/core/src/CheckboxInput/XDSCheckboxInput.tsx@@ -250,7 +250,12 @@ export interface XDSCheckboxInputProps {*/isDisabled?: boolean;/**- * Whether the checkbox is required.+ * Whether the field is optional. Mutually exclusive with isRequired.+ * @default false+ */+ isOptional?: boolean;+ /**+ * Whether the checkbox is required. Mutually exclusive with isOptional.* @default false*/isRequired?: boolean;@@ -272,7 +277,7 @@ export interface XDSCheckboxInputProps {/*** Icon to display before the label text.*/- startIcon?: XDSIconType;+ labelIcon?: XDSIconType;/*** Status indicator for the checkbox.* When set with a message, displays a colored message box below the checkbox.@@ -312,11 +317,12 @@ export const XDSCheckboxInput = forwardRef<isLoading = false,value,isDisabled = false,+ isOptional = false,isRequired = false,size = 'md',onFocus,onBlur,- startIcon,+ labelIcon,status,},ref,@@ -439,9 +445,11 @@ export const XDSCheckboxInput = forwardRef<inputID={id}isLabelHidden={isLabelHidden}isDisabled={isDisabled}- startIcon={startIcon}+ isOptional={isOptional}+ isRequired={isRequired}+ labelIcon={labelIcon}/>- {description && (+ {description && !isLabelHidden && (<span id={descriptionID} {...stylex.props(styles.description)}>{description}</span>diff --git a/packages/core/src/DateInput/XDSDateInput.tsx b/packages/core/src/DateInput/XDSDateInput.tsxindex aa6487ecb5..13d15fb8c0 100644--- a/packages/core/src/DateInput/XDSDateInput.tsx+++ b/packages/core/src/DateInput/XDSDateInput.tsx@@ -324,6 +324,11 @@ export interface XDSDateInputProps {*/status?: XDSInputStatus;+ /**+ * Tooltip text to display in an info icon at the end of the label.+ */+ labelTooltip?: string;+/*** Number of months to display in the calendar popover.* @default 1@@ -362,6 +367,7 @@ export const XDSDateInput = forwardRef<HTMLInputElement, XDSDateInputProps>(placeholder = 'Select a date',size = 'md',status,+ labelTooltip,numberOfMonths = 1,},ref,@@ -557,7 +563,8 @@ export const XDSDateInput = forwardRef<HTMLInputElement, XDSDateInputProps>(messageID: status.message ? statusMessageID : undefined,}: undefined- }>+ }+ labelTooltip={labelTooltip}><divref={popover.triggerRef}{...stylex.props(diff --git a/packages/core/src/Field/XDSField.test.tsx b/packages/core/src/Field/XDSField.test.tsxindex 1e60319759..5cc9a8c4a1 100644--- a/packages/core/src/Field/XDSField.test.tsx+++ b/packages/core/src/Field/XDSField.test.tsx@@ -62,6 +62,20 @@ describe('XDSField', () => {expect(screen.getByLabelText('Search')).toBeInTheDocument();});+ it('hides description when isLabelHidden is true', () => {+ render(+ <XDSField+ label="Search"+ isLabelHidden+ description="Search for items"+ inputID="search-input"+ descriptionID="search-desc">+ <input id="search-input" />+ </XDSField>,+ );+ expect(screen.queryByText('Search for items')).not.toBeInTheDocument();+ });+it('shows label visually by default', () => {render(<XDSField label="Email" inputID="email-input">diff --git a/packages/core/src/Field/XDSField.tsx b/packages/core/src/Field/XDSField.tsxindex a566c2195e..61e21adb27 100644--- a/packages/core/src/Field/XDSField.tsx+++ b/packages/core/src/Field/XDSField.tsx@@ -120,12 +120,13 @@ export interface XDSFieldProps extends Omit<*/label: string;/**- * Whether to visually hide the label (still accessible to screen readers).+ * Whether to visually hide the label and description (still accessible to screen readers).* @default false*/isLabelHidden?: boolean;/*** Description text displayed between the label and input.+ * Hidden when isLabelHidden is true.*/description?: string;/**@@ -149,7 +150,7 @@ export interface XDSFieldProps extends Omit</*** Icon to display before the label text.*/- labelStartIcon?: XDSIconType;+ labelIcon?: XDSIconType;/*** Status indicator for the field.* When set with a message, displays a colored message box below the input.@@ -194,7 +195,7 @@ export const XDSField = forwardRef<HTMLDivElement, XDSFieldProps>(descriptionID,isOptional = false,isRequired = false,- labelStartIcon,+ labelIcon,status,labelTooltip,statusVariant = 'attached',@@ -219,10 +220,10 @@ export const XDSField = forwardRef<HTMLDivElement, XDSFieldProps>(isLabelHidden={isLabelHidden}isOptional={isOptional}isRequired={isRequired}- startIcon={labelStartIcon}- tooltip={labelTooltip}+ labelIcon={labelIcon}+ labelTooltip={labelTooltip}/>- {description && (+ {description && !isLabelHidden && (<spanid={descriptionID}{...stylex.props(styles.description, descriptionOverride)}>diff --git a/packages/core/src/Field/XDSFieldLabel.test.tsx b/packages/core/src/Field/XDSFieldLabel.test.tsxindex 0b9d2cd453..8351ae79ca 100644--- a/packages/core/src/Field/XDSFieldLabel.test.tsx+++ b/packages/core/src/Field/XDSFieldLabel.test.tsx@@ -42,12 +42,12 @@ describe('XDSFieldLabel', () => {expect(screen.queryByText(/Required/)).not.toBeInTheDocument();});- it('renders startIcon when provided', () => {+ it('renders labelIcon when provided', () => {render(<XDSFieldLabellabel="Starred"inputID="starred-input"- startIcon={StarIcon}+ labelIcon={StarIcon}/>,);const svg = document.querySelector('svg');@@ -60,12 +60,12 @@ describe('XDSFieldLabel', () => {expect(ref).toHaveBeenCalledWith(expect.any(HTMLLabelElement));});- it('renders tooltip info icon when tooltip prop is provided', () => {+ it('renders tooltip info icon when labelTooltip prop is provided', () => {render(<XDSFieldLabellabel="Help"inputID="help-input"- tooltip="This is helpful information"+ labelTooltip="This is helpful information"/>,);// Two SVGs: the info icon is wrapped in tooltip@@ -73,19 +73,19 @@ describe('XDSFieldLabel', () => {expect(svgs.length).toBeGreaterThan(0);});- it('does not render extra icon when tooltip is not provided', () => {+ it('does not render extra icon when labelTooltip is not provided', () => {render(<XDSFieldLabel label="Name" inputID="name-input" />);// No SVGs should be present when no icons are providedexpect(document.querySelector('svg')).not.toBeInTheDocument();});- it('renders tooltip with Optional indicator together', () => {+ it('renders labelTooltip with Optional indicator together', () => {render(<XDSFieldLabellabel="Field"inputID="field-input"isOptional- tooltip="Help text"+ labelTooltip="Help text"/>,);expect(screen.getByText(/Optional/)).toBeInTheDocument();diff --git a/packages/core/src/Field/XDSFieldLabel.tsx b/packages/core/src/Field/XDSFieldLabel.tsxindex dbcc5b7e36..926ebcc39f 100644--- a/packages/core/src/Field/XDSFieldLabel.tsx+++ b/packages/core/src/Field/XDSFieldLabel.tsx@@ -93,11 +93,11 @@ export interface XDSFieldLabelProps {/*** Icon to display before the label text.*/- startIcon?: XDSIconType;+ labelIcon?: XDSIconType;/*** Tooltip text to display in an info icon at the end of the label.*/- tooltip?: string;+ labelTooltip?: string;}/**@@ -118,8 +118,8 @@ export const XDSFieldLabel = forwardRef<HTMLLabelElement, XDSFieldLabelProps>(isDisabled = false,isOptional = false,isRequired = false,- startIcon,- tooltip,+ labelIcon,+ labelTooltip,},ref,) => {@@ -135,9 +135,9 @@ export const XDSFieldLabel = forwardRef<HTMLLabelElement, XDSFieldLabelProps>(isDisabled && styles.labelDisabled,isLabelHidden && styles.labelHidden,)}>- {startIcon && (+ {labelIcon && (<XDSIcon- icon={startIcon}+ icon={labelIcon}size="sm"color={isDisabled ? 'disabled' : 'primary'}/>@@ -149,8 +149,8 @@ export const XDSFieldLabel = forwardRef<HTMLLabelElement, XDSFieldLabelProps>(∙ {statusText}</span>)}- {tooltip && (- <XDSTooltip content={tooltip} placement="above">+ {labelTooltip && (+ <XDSTooltip content={labelTooltip} placement="above"><XDSIconicon="info"size="sm"diff --git a/packages/core/src/NumberInput/XDSNumberInput.test.tsx b/packages/core/src/NumberInput/XDSNumberInput.test.tsxindex cb0b29dbaf..c14dfb1a23 100644--- a/packages/core/src/NumberInput/XDSNumberInput.test.tsx+++ b/packages/core/src/NumberInput/XDSNumberInput.test.tsx@@ -495,19 +495,19 @@ describe('XDSNumberInput', () => {});});- it('renders tooltip info icon when tooltip is provided', () => {+ it('renders tooltip info icon when labelTooltip is provided', () => {render(<XDSNumberInputlabel="Help"value={null}onChange={() => {}}- tooltip="Helpful info"+ labelTooltip="Helpful info"/>,);expect(document.querySelector('svg')).toBeInTheDocument();});- it('does not render tooltip icon when tooltip is not provided', () => {+ it('does not render tooltip icon when labelTooltip is not provided', () => {render(<XDSNumberInput label="Quantity" value={null} onChange={() => {}} />,);diff --git a/packages/core/src/NumberInput/XDSNumberInput.tsx b/packages/core/src/NumberInput/XDSNumberInput.tsxindex 39f65b9660..f2d9cf2e12 100644--- a/packages/core/src/NumberInput/XDSNumberInput.tsx+++ b/packages/core/src/NumberInput/XDSNumberInput.tsx@@ -275,7 +275,7 @@ export interface XDSNumberInputProps {/*** Tooltip text to display in an info icon at the end of the label.*/- tooltip?: string;+ labelTooltip?: string;/*** Whether to automatically focus the input on mount.* @default false@@ -392,7 +392,7 @@ export const XDSNumberInput = forwardRef<HTMLInputElement, XDSNumberInputProps>(onChange,value,placeholder,- tooltip,+ labelTooltip,hasAutoFocus = false,htmlName,autoComplete,@@ -550,7 +550,7 @@ export const XDSNumberInput = forwardRef<HTMLInputElement, XDSNumberInputProps>(descriptionID={description ? descriptionID : undefined}isOptional={isOptional}isRequired={isRequired}- labelStartIcon={labelIcon}+ labelIcon={labelIcon}status={status? {@@ -560,7 +560,7 @@ export const XDSNumberInput = forwardRef<HTMLInputElement, XDSNumberInputProps>(}: undefined}- labelTooltip={tooltip}>+ labelTooltip={labelTooltip}><div{...stylex.props(styles.wrapper,diff --git a/packages/core/src/Switch/XDSSwitch.tsx b/packages/core/src/Switch/XDSSwitch.tsxindex ce17e1bd85..3f22926a71 100644--- a/packages/core/src/Switch/XDSSwitch.tsx+++ b/packages/core/src/Switch/XDSSwitch.tsx@@ -380,10 +380,10 @@ export const XDSSwitch = forwardRef<HTMLInputElement, XDSSwitchProps>(isDisabled={isDisabled}isOptional={isOptional}isRequired={isRequired}- startIcon={labelIcon}- tooltip={labelTooltip}+ labelIcon={labelIcon}+ labelTooltip={labelTooltip}/>- {description && (+ {description && !isLabelHidden && (<span id={descriptionID} {...stylex.props(styles.description)}>{description}</span>diff --git a/packages/core/src/TimeInput/XDSTimeInput.tsx b/packages/core/src/TimeInput/XDSTimeInput.tsxindex f6da3f437a..9ff73f5daf 100644--- a/packages/core/src/TimeInput/XDSTimeInput.tsx+++ b/packages/core/src/TimeInput/XDSTimeInput.tsx@@ -347,6 +347,11 @@ export interface XDSTimeInputProps {* If message is provided, displays below the input.*/status?: XDSInputStatus;++ /**+ * Tooltip text to display in an info icon at the end of the label.+ */+ labelTooltip?: string;}/**@@ -385,6 +390,7 @@ export const XDSTimeInput = forwardRef<HTMLInputElement, XDSTimeInputProps>(placeholder = 'Select a time',size = 'md',status,+ labelTooltip,},ref,) => {@@ -598,7 +604,8 @@ export const XDSTimeInput = forwardRef<HTMLInputElement, XDSTimeInputProps>(messageID: status.message ? statusMessageID : undefined,}: undefined- }>+ }+ labelTooltip={labelTooltip}><div{...stylex.props(styles.wrapper,