diff --git a/.changeset/happy-glasses-work.md b/.changeset/happy-glasses-work.md new file mode 100644 index 0000000000..d3bf39139c --- /dev/null +++ b/.changeset/happy-glasses-work.md @@ -0,0 +1,5 @@ +--- +'@sumup/circuit-ui': minor +--- + +Added a `hideLabel` prop to the ImageInput component (defaulting to `true` to match the existing behavior) and added an `optionalLabel` prop to indicate to users whether the input is required. diff --git a/packages/circuit-ui/components/Field/Field.module.css b/packages/circuit-ui/components/Field/Field.module.css index f74aeb7e08..a0c309f138 100644 --- a/packages/circuit-ui/components/Field/Field.module.css +++ b/packages/circuit-ui/components/Field/Field.module.css @@ -8,13 +8,13 @@ .label, .legend { display: block; - font-size: var(--cui-typography-body-two-font-size); - line-height: var(--cui-typography-body-two-line-height); } .label-text { - display: inline-block; + display: block; margin-bottom: var(--cui-spacings-bit); + font-size: var(--cui-typography-body-two-font-size); + line-height: var(--cui-typography-body-two-line-height); } [disabled] .label-text, diff --git a/packages/circuit-ui/components/Field/Field.tsx b/packages/circuit-ui/components/Field/Field.tsx index 9d3d243c0b..b3c45154ab 100644 --- a/packages/circuit-ui/components/Field/Field.tsx +++ b/packages/circuit-ui/components/Field/Field.tsx @@ -122,6 +122,7 @@ export function FieldLabelText({ hideLabel, optionalLabel, required, + ...props }: FieldLabelTextProps) { return ( {label} {optionalLabel && !required ? ( diff --git a/packages/circuit-ui/components/ImageInput/ImageInput.spec.tsx b/packages/circuit-ui/components/ImageInput/ImageInput.spec.tsx index 07e5e08ded..ad8ca9878f 100644 --- a/packages/circuit-ui/components/ImageInput/ImageInput.spec.tsx +++ b/packages/circuit-ui/components/ImageInput/ImageInput.spec.tsx @@ -105,7 +105,9 @@ describe('ImageInput', () => { */ it('should support dragging and dropping an image', async () => { render(); - const labelEl = screen.getByText(defaultProps.label); + const labelEl = screen.getByText(defaultProps.label, { + ignore: '[aria-hidden="true"]', + }); fireEvent.drop(labelEl, { dataTransfer: { files: [file] } }); diff --git a/packages/circuit-ui/components/ImageInput/ImageInput.stories.tsx b/packages/circuit-ui/components/ImageInput/ImageInput.stories.tsx index 16478468c7..11ec8ec1cd 100644 --- a/packages/circuit-ui/components/ImageInput/ImageInput.stories.tsx +++ b/packages/circuit-ui/components/ImageInput/ImageInput.stories.tsx @@ -75,6 +75,7 @@ export const Disabled = (args: ImageInputProps) => ( disabled loadingLabel="Uploading" component={(props) => } + hideLabel={false} /> ); diff --git a/packages/circuit-ui/components/ImageInput/ImageInput.tsx b/packages/circuit-ui/components/ImageInput/ImageInput.tsx index 20d3be2dfc..9b57e87b8c 100644 --- a/packages/circuit-ui/components/ImageInput/ImageInput.tsx +++ b/packages/circuit-ui/components/ImageInput/ImageInput.tsx @@ -33,6 +33,7 @@ import { FieldWrapper, FieldLabel, FieldValidationHint, + FieldLabelText, } from '../Field/index.js'; import { IconButton } from '../Button/index.js'; import { Spinner } from '../Spinner/index.js'; @@ -89,6 +90,15 @@ export interface ImageInputProps * An information or error message, displayed below the input. */ validationHint?: string; + /** + * Label to indicate that the input is optional. Only displayed when the + * `required` prop is falsy. + */ + optionalLabel?: string; + /** + * Visually hide the label. Default: `true`. + */ + hideLabel?: boolean; } /** @@ -104,7 +114,10 @@ export const ImageInput = ({ disabled, validationHint, invalid = false, + required, + optionalLabel, loadingLabel, + hideLabel = true, 'component': Component, className, style, @@ -231,6 +244,13 @@ export const ImageInput = ({ return ( +