diff --git a/packages/@react-spectrum/s2/src/Checkbox.tsx b/packages/@react-spectrum/s2/src/Checkbox.tsx index 0922dcc028e..af1d9ba6949 100644 --- a/packages/@react-spectrum/s2/src/Checkbox.tsx +++ b/packages/@react-spectrum/s2/src/Checkbox.tsx @@ -53,7 +53,10 @@ export const CheckboxContext = createContext const field = style({ display: 'grid', - gridTemplateColumns: ['max-content', '1fr'], + gridTemplateColumns: { + default: ['max-content', '1fr'], + isNoVisibleLabel: ['max-content'] + }, columnGap: 'text-to-control', alignContent: 'start', width: { @@ -182,7 +185,7 @@ export const Checkbox = forwardRef(function Checkbox({children, ...props}: Check ref={domRef} inputRef={inputRef} style={props.UNSAFE_style} - className={(props.UNSAFE_className || '') + field({size: props.size || 'M', isInCheckboxGroup}, props.styles)}> + className={(props.UNSAFE_className || '') + field({size: props.size || 'M', isInCheckboxGroup, isNoVisibleLabel: !children}, props.styles)}> {({isDisabled, isInvalid}) => (<> wrapper({...renderProps, isInForm, size: props.size || 'M'})}> {renderProps => { diff --git a/packages/@react-spectrum/s2/src/RadioGroup.tsx b/packages/@react-spectrum/s2/src/RadioGroup.tsx index 21a054d129d..603e267aecb 100644 --- a/packages/@react-spectrum/s2/src/RadioGroup.tsx +++ b/packages/@react-spectrum/s2/src/RadioGroup.tsx @@ -175,7 +175,10 @@ interface RenderProps extends RadioRenderProps, ContextProps {} const radioField = style({ display: 'grid', - gridTemplateColumns: ['max-content', '1fr'], + gridTemplateColumns: { + default: ['max-content', '1fr'], + isNoVisibleLabel: ['max-content'] + }, columnGap: 'text-to-control', alignContent: 'start', font: controlFont(), @@ -277,7 +280,7 @@ export const Radio = /*#__PURE__*/ forwardRef(function Radio(props: RadioProps, ref={domRef} inputRef={inputRef} style={UNSAFE_style} - className={renderProps => UNSAFE_className + radioField({...renderProps, isInForm, size}, allProps.styles)}> + className={renderProps => UNSAFE_className + radioField({...renderProps, isInForm, size, isNoVisibleLabel: !children}, allProps.styles)}> {renderProps => ( <> wrapper({...renderProps, isInForm, size})}> diff --git a/packages/@react-spectrum/s2/src/Switch.tsx b/packages/@react-spectrum/s2/src/Switch.tsx index 69186ab32bb..aaaa182cdb4 100644 --- a/packages/@react-spectrum/s2/src/Switch.tsx +++ b/packages/@react-spectrum/s2/src/Switch.tsx @@ -47,7 +47,10 @@ export const SwitchContext = createContext, Fo const field = style({ display: 'grid', - gridTemplateColumns: ['max-content', '1fr'], + gridTemplateColumns: { + default: ['max-content', '1fr'], + isNoVisibleLabel: ['max-content'] + }, columnGap: 'text-to-control', width: 'fit', font: controlFont(), @@ -183,7 +186,7 @@ export const Switch = /*#__PURE__*/ forwardRef(function Switch(props: SwitchProp ref={domRef} inputRef={inputRef} style={UNSAFE_style} - className={renderProps => UNSAFE_className + field({...renderProps, isInForm, size: props.size || 'M'}, props.styles)}> + className={renderProps => UNSAFE_className + field({...renderProps, isInForm, size: props.size || 'M', isNoVisibleLabel: !children}, props.styles)}> {({isDisabled, isInvalid}) => (<> wrapper({...renderProps, isInForm, size: props.size || 'M'})}> {renderProps => (