Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnitControl: Normalize wrapper classnames by removing outer wrapper #45139

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default function BorderRadiusControl( { onChange, values } ) {
{ isLinked ? (
<>
<AllInputControl
__unstableWrapperClassName="components-border-radius-control__unit-control"
className="components-border-radius-control__unit-control"
values={ values }
min={ MIN_BORDER_RADIUS_VALUE }
onChange={ onChange }
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/border-control/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
StyledLabel,
} from '../base-control/styles/base-control-styles';
import {
Root as UnitControlWrapper,
ValueInput as UnitControlWrapper,
UnitSelect,
} from '../unit-control/styles/unit-control-styles';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ exports[`DimensionControl rendering renders with custom sizes 1`] = `
-webkit-justify-content: space-between;
justify-content: space-between;
height: 100%;
box-sizing: border-box;
position: relative;
border-radius: 2px;
padding-top: 0;
Expand Down Expand Up @@ -309,6 +310,7 @@ exports[`DimensionControl rendering renders with defaults 1`] = `
-webkit-justify-content: space-between;
justify-content: space-between;
height: 100%;
box-sizing: border-box;
position: relative;
border-radius: 2px;
padding-top: 0;
Expand Down Expand Up @@ -590,6 +592,7 @@ exports[`DimensionControl rendering renders with icon and custom icon label 1`]
-webkit-justify-content: space-between;
justify-content: space-between;
height: 100%;
box-sizing: border-box;
position: relative;
border-radius: 2px;
padding-top: 0;
Expand Down Expand Up @@ -883,6 +886,7 @@ exports[`DimensionControl rendering renders with icon and default icon label 1`]
-webkit-justify-content: space-between;
justify-content: space-between;
height: 100%;
box-sizing: border-box;
position: relative;
border-radius: 2px;
padding-top: 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const rootFocusedStyles = ( { isFocused }: RootProps ) => {
};

export const Root = styled( Flex )< RootProps >`
box-sizing: border-box;
position: relative;
border-radius: 2px;
padding-top: 0;
Expand Down
54 changes: 26 additions & 28 deletions packages/components/src/unit-control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { __ } from '@wordpress/i18n';
*/
import type { WordPressComponentProps } from '../ui/context';
import * as inputControlActionTypes from '../input-control/reducer/actions';
import { Root, ValueInput } from './styles/unit-control-styles';
import { ValueInput } from './styles/unit-control-styles';
import UnitSelectControl from './unit-select-control';
import {
CSS_UNITS,
Expand Down Expand Up @@ -58,12 +58,10 @@ function UnforwardedUnitControl(
onChange: onChangeProp,
onUnitChange,
size = 'default',
style,
unit: unitProp,
units: unitsProp = CSS_UNITS,
value: valueProp,
onBlur: onBlurProp,
__unstableWrapperClassName,
...props
} = unitControlProps;

Expand Down Expand Up @@ -106,10 +104,12 @@ function UnforwardedUnitControl(
// Stores parsed value for hand-off in state reducer.
const refParsedQuantity = useRef< number | undefined >( undefined );

const classes = classnames( 'components-unit-control', className );
const wrapperClasses = classnames(
const classes = classnames(
'components-unit-control',
// This class is added for legacy purposes to maintain it on the outer
// wrapper. See: https://github.com/WordPress/gutenberg/pull/45139
'components-unit-control-wrapper',
__unstableWrapperClassName
className
);

const handleOnQuantityChange = (
Expand Down Expand Up @@ -182,7 +182,7 @@ function UnforwardedUnitControl(
: undefined;
const changeProps = { event, data };

// The `onChange` callback already gets called, no need to call it explicitely.
// The `onChange` callback already gets called, no need to call it explicitly.
onUnitChange?.( validParsedUnit, changeProps );

setUnit( validParsedUnit );
Expand Down Expand Up @@ -263,27 +263,25 @@ function UnforwardedUnitControl(
}

return (
<Root className={ wrapperClasses } style={ style }>
<ValueInput
type={ isPressEnterToChange ? 'text' : 'number' }
{ ...props }
autoComplete={ autoComplete }
className={ classes }
disabled={ disabled }
hideHTMLArrows
isPressEnterToChange={ isPressEnterToChange }
label={ label }
onBlur={ handleOnBlur }
onKeyDown={ handleOnKeyDown }
onChange={ handleOnQuantityChange }
ref={ forwardedRef }
size={ size }
suffix={ inputSuffix }
value={ parsedQuantity ?? '' }
step={ step }
__unstableStateReducer={ stateReducer }
/>
</Root>
<ValueInput
type={ isPressEnterToChange ? 'text' : 'number' }
{ ...props }
autoComplete={ autoComplete }
className={ classes }
disabled={ disabled }
hideHTMLArrows
isPressEnterToChange={ isPressEnterToChange }
label={ label }
onBlur={ handleOnBlur }
onKeyDown={ handleOnKeyDown }
onChange={ handleOnQuantityChange }
ref={ forwardedRef }
size={ size }
suffix={ inputSuffix }
value={ parsedQuantity ?? '' }
step={ step }
__unstableStateReducer={ stateReducer }
/>
);
}

Expand Down
14 changes: 4 additions & 10 deletions packages/components/src/unit-control/styles/unit-control-styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,6 @@ type SelectProps = {
selectSize: SelectSize;
};

export const Root = styled.div`
box-sizing: border-box;
ciampo marked this conversation as resolved.
Show resolved Hide resolved
position: relative;

/* Target the InputControl's backdrop and make focus styles smoother. */
&&& ${ BackdropUI } {
transition: box-shadow 0.1s linear;
}
`;

// TODO: Resolve need to use &&& to increase specificity
// https://github.com/WordPress/gutenberg/issues/18483

Expand All @@ -37,6 +27,10 @@ export const ValueInput = styled( NumberControl )`
display: block;
width: 100%;
}

${ BackdropUI } {
transition: box-shadow 0.1s linear;
}
}
`;

Expand Down
4 changes: 0 additions & 4 deletions packages/components/src/unit-control/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,4 @@ export type UnitControlProps = Omit< UnitSelectControlProps, 'unit' > &
* Callback when either the quantity or the unit inputs lose focus.
*/
onBlur?: FocusEventHandler< HTMLInputElement | HTMLSelectElement >;
/**
* Custom CSS class to apply to the unit control's outer wrapper.
*/
__unstableWrapperClassName?: string;
};