Skip to content

Commit ac17c63

Browse files
BorderControl: Update labelling, tooltips and wrap with fieldset and legend (#42348)
1 parent 0fb5971 commit ac17c63

File tree

5 files changed

+41
-11
lines changed

5 files changed

+41
-11
lines changed

packages/components/src/base-control/styles/base-control-styles.ts

+5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ const labelStyles = css`
3939

4040
export const StyledLabel = styled.label`
4141
${ labelStyles }
42+
/**
43+
* Removes Chrome/Safari/Firefox user agent stylesheet padding from
44+
* StyledLabel when it is rendered as a legend.
45+
*/
46+
padding: 0;
4247
`;
4348

4449
const deprecatedMarginHelp = ( { __nextHasNoMarginBottom = false } ) => {

packages/components/src/border-control/border-control-dropdown/component.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ const BorderControlDropdown = (
176176
variant="tertiary"
177177
aria-label={ toggleAriaLabel }
178178
position={ dropdownPosition }
179+
label={ __( 'Border color and style picker' ) }
180+
showTooltip={ true }
179181
>
180182
<span className={ indicatorWrapperClassName }>
181183
<ColorIndicator

packages/components/src/border-control/border-control/component.tsx

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* WordPress dependencies
3+
*/
4+
import { __ } from '@wordpress/i18n';
5+
16
/**
27
* Internal dependencies
38
*/
@@ -21,9 +26,9 @@ const BorderLabel = ( props: LabelProps ) => {
2126
}
2227

2328
return hideLabelFromVision ? (
24-
<VisuallyHidden as="label">{ label }</VisuallyHidden>
29+
<VisuallyHidden as="legend">{ label }</VisuallyHidden>
2530
) : (
26-
<StyledLabel>{ label }</StyledLabel>
31+
<StyledLabel as="legend">{ label }</StyledLabel>
2732
);
2833
};
2934

@@ -59,7 +64,7 @@ const UnconnectedBorderControl = (
5964
} = useBorderControl( props );
6065

6166
return (
62-
<View { ...otherProps } ref={ forwardedRef }>
67+
<View as="fieldset" { ...otherProps } ref={ forwardedRef }>
6368
<BorderLabel
6469
label={ label }
6570
hideLabelFromVision={ hideLabelFromVision }
@@ -85,6 +90,8 @@ const UnconnectedBorderControl = (
8590
__next36pxDefaultSize={ __next36pxDefaultSize }
8691
/>
8792
<UnitControl
93+
label={ __( 'Border width' ) }
94+
hideLabelFromVision
8895
className={ widthControlClassName }
8996
min={ 0 }
9097
onChange={ onWidthChange }
@@ -94,6 +101,8 @@ const UnconnectedBorderControl = (
94101
</HStack>
95102
{ withSlider && (
96103
<RangeControl
104+
label={ __( 'Border width' ) }
105+
hideLabelFromVision
97106
className={ sliderClassName }
98107
initialPosition={ 0 }
99108
max={ 100 }

packages/components/src/border-control/styles.ts

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ const focusBoxShadow = css`
3131

3232
export const borderControl = css`
3333
position: relative;
34+
border: 0;
35+
padding: 0;
36+
margin: 0;
3437
`;
3538

3639
export const innerWrapper = () => css`

packages/components/src/border-control/test/index.js

+19-8
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,15 @@ const clickButton = ( name ) => {
5858
fireEvent.click( getButton( name ) );
5959
};
6060

61+
const getSliderInput = () => {
62+
return screen.getByRole( 'slider', { name: 'Border width' } );
63+
};
64+
65+
const getWidthInput = () => {
66+
return screen.getByRole( 'spinbutton', { name: 'Border width' } );
67+
};
6168
const setWidthInput = ( value ) => {
62-
const widthInput = screen.getByRole( 'spinbutton' );
69+
const widthInput = getWidthInput();
6370
widthInput.focus();
6471
fireEvent.change( widthInput, { target: { value } } );
6572
};
@@ -73,9 +80,13 @@ describe( 'BorderControl', () => {
7380

7481
const label = screen.getByText( props.label );
7582
const colorButton = screen.getByLabelText( toggleLabelRegex );
76-
const widthInput = screen.getByRole( 'spinbutton' );
77-
const unitSelect = screen.getByRole( 'combobox' );
78-
const slider = screen.queryByRole( 'slider' );
83+
const widthInput = getWidthInput();
84+
const unitSelect = screen.getByRole( 'combobox', {
85+
name: 'Select unit',
86+
} );
87+
const slider = screen.queryByRole( 'slider', {
88+
name: 'Border width',
89+
} );
7990

8091
expect( label ).toBeInTheDocument();
8192
expect( colorButton ).toBeInTheDocument();
@@ -100,13 +111,13 @@ describe( 'BorderControl', () => {
100111
it( 'should render with slider', () => {
101112
renderBorderControl( { withSlider: true } );
102113

103-
const slider = screen.getByRole( 'slider' );
114+
const slider = getSliderInput();
104115
expect( slider ).toBeInTheDocument();
105116
} );
106117

107118
it( 'should render placeholder in UnitControl', () => {
108119
renderBorderControl( { placeholder: 'Mixed' } );
109-
const widthInput = screen.getByRole( 'spinbutton' );
120+
const widthInput = getWidthInput();
110121

111122
expect( widthInput ).toHaveAttribute( 'placeholder', 'Mixed' );
112123
} );
@@ -262,7 +273,7 @@ describe( 'BorderControl', () => {
262273
it( 'should update width with slider value', () => {
263274
const { rerender } = renderBorderControl( { withSlider: true } );
264275

265-
const slider = screen.getByRole( 'slider' );
276+
const slider = getSliderInput();
266277
fireEvent.change( slider, { target: { value: '5' } } );
267278

268279
expect( props.onChange ).toHaveBeenNthCalledWith( 1, {
@@ -271,7 +282,7 @@ describe( 'BorderControl', () => {
271282
} );
272283

273284
rerenderBorderControl( rerender, { withSlider: true } );
274-
const widthInput = screen.getByRole( 'spinbutton' );
285+
const widthInput = getWidthInput();
275286

276287
expect( widthInput.value ).toEqual( '5' );
277288
} );

0 commit comments

Comments
 (0)