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

Remove the duplicated title in background, text and link views in Global Styles #35583

Merged
merged 5 commits into from
Oct 25, 2021
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 @@ -32,13 +32,38 @@ exports[`ColorPaletteControl matches the snapshot 1`] = `
}

.emotion-4>*+*:not( marquee ) {
margin-top: calc(4px * 2);
margin-top: calc(4px * 1);
}

.emotion-4>* {
min-height: 0;
}

.emotion-6 {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-align-items: normal;
-webkit-box-align: normal;
-ms-flex-align: normal;
align-items: normal;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
-webkit-box-pack: justify;
-webkit-justify-content: space-between;
justify-content: space-between;
}

.emotion-6>*+*:not( marquee ) {
margin-top: calc(4px * 3);
}

.emotion-6>* {
min-height: 0;
}

<div
className="components-base-control block-editor-color-gradient-control emotion-0 emotion-1"
>
Expand All @@ -59,89 +84,89 @@ exports[`ColorPaletteControl matches the snapshot 1`] = `
className="components-base-control__label"
>
Test Color
<span
aria-label="(Color: #f00)"
className="component-color-indicator"
style={
Object {
"background": "#f00",
}
}
/>
</span>
</div>
</legend>
<div
className="components-circular-option-picker"
className="components-flex components-h-stack components-v-stack emotion-6 emotion-5"
data-wp-c16t={true}
data-wp-component="VStack"
>
<div
className="components-circular-option-picker__swatches"
className="components-dropdown"
tabIndex="-1"
>
<button
aria-expanded={false}
aria-haspopup="true"
aria-label="Custom color picker"
className="components-color-palette__custom-color"
onClick={[Function]}
style={
Object {
"background": "#f00",
}
}
>
#f00
</button>
</div>
<div
className="components-circular-option-picker"
>
<div
className="components-circular-option-picker__option-wrapper"
className="components-circular-option-picker__swatches"
>
<button
aria-describedby={null}
aria-label="Color: red"
aria-pressed={true}
className="components-button components-circular-option-picker__option is-pressed"
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
onMouseDown={[Function]}
onMouseEnter={[Function]}
onMouseLeave={[Function]}
style={
Object {
"backgroundColor": "#f00",
"color": "#f00",
}
}
type="button"
/>
<svg
aria-hidden={true}
fill="#000"
focusable={false}
height={24}
role="img"
viewBox="0 0 24 24"
width={24}
xmlns="http://www.w3.org/2000/svg"
<div
className="components-circular-option-picker__option-wrapper"
>
<path
d="M16.7 7.1l-6.3 8.5-3.3-2.5-.9 1.2 4.5 3.4L17.9 8z"
<button
aria-describedby={null}
aria-label="Color: red"
aria-pressed={true}
className="components-button components-circular-option-picker__option is-pressed"
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
onMouseDown={[Function]}
onMouseEnter={[Function]}
onMouseLeave={[Function]}
style={
Object {
"backgroundColor": "#f00",
"color": "#f00",
}
}
type="button"
/>
</svg>
<svg
aria-hidden={true}
fill="#000"
focusable={false}
height={24}
role="img"
viewBox="0 0 24 24"
width={24}
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M16.7 7.1l-6.3 8.5-3.3-2.5-.9 1.2 4.5 3.4L17.9 8z"
/>
</svg>
</div>
</div>
</div>
<div
className="components-circular-option-picker__custom-clear-wrapper"
>
<div
className="components-dropdown components-circular-option-picker__dropdown-link-action"
tabIndex="-1"
className="components-circular-option-picker__custom-clear-wrapper"
>
<button
aria-describedby={null}
aria-expanded={false}
aria-haspopup="true"
aria-label="Custom color picker"
className="components-button is-link"
className="components-button components-circular-option-picker__clear is-secondary is-small"
onClick={[Function]}
type="button"
>
Custom color
Clear
</button>
</div>
<button
aria-describedby={null}
className="components-button components-circular-option-picker__clear is-secondary is-small"
onClick={[Function]}
type="button"
>
Clear
</button>
</div>
</div>
</div>
Expand Down
74 changes: 12 additions & 62 deletions packages/block-editor/src/components/colors-gradients/control.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,71 +13,23 @@ import {
__experimentalVStack as VStack,
__experimentalToggleGroupControl as ToggleGroupControl,
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
ColorIndicator,
ColorPalette,
GradientPicker,
} from '@wordpress/components';
import { sprintf, __ } from '@wordpress/i18n';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import { getColorObjectByColorValue } from '../colors';
import { __experimentalGetGradientObjectByGradientValue } from '../gradients';
import useSetting from '../use-setting';

// translators: first %s: the color name or value (e.g. red or #ff0000)
const colorIndicatorAriaLabel = __( '(Color: %s)' );

// translators: first %s: the gradient name or value (e.g. red to green or linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)
const gradientIndicatorAriaLabel = __( '(Gradient: %s)' );

const colorsAndGradientKeys = [
'colors',
'disableCustomColors',
'gradients',
'disableCustomGradients',
];

function VisualLabel( {
colors,
gradients,
label,
currentTab,
colorValue,
gradientValue,
} ) {
let value, ariaLabel;
if ( currentTab === 'color' ) {
if ( colorValue ) {
value = colorValue;
const colorObject = getColorObjectByColorValue( colors, value );
const colorName = colorObject && colorObject.name;
ariaLabel = sprintf( colorIndicatorAriaLabel, colorName || value );
}
} else if ( currentTab === 'gradient' && gradientValue ) {
value = gradientValue;
const gradientObject = __experimentalGetGradientObjectByGradientValue(
gradients,
value
);
const gradientName = gradientObject && gradientObject.name;
ariaLabel = sprintf(
gradientIndicatorAriaLabel,
gradientName || value
);
}

return (
<>
{ label }
{ !! value && (
<ColorIndicator colorValue={ value } aria-label={ ariaLabel } />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would deleting the code that computes an accessible color label be an accessibility regression?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know for sure but I don't feel like it since that label is only read when the element is reached which is not the case here but.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I guess we still need to work on replacing / consolidating the color indicator components (tracked in #35093), so probably adding solid accessible text should be done there as well

) }
</>
);
}

function ColorGradientControlInner( {
colors,
gradients,
Expand All @@ -90,6 +42,7 @@ function ColorGradientControlInner( {
colorValue,
gradientValue,
clearable,
showTitle = true,
} ) {
const canChooseAColor =
onColorChange && ( ! isEmpty( colors ) || ! disableCustomColors );
Expand All @@ -111,19 +64,16 @@ function ColorGradientControlInner( {
) }
>
<fieldset>
<VStack space={ 3 }>
<legend>
<div className="block-editor-color-gradient-control__color-indicator">
<BaseControl.VisualLabel>
<VisualLabel
currentTab={ currentTab }
label={ label }
colorValue={ colorValue }
gradientValue={ gradientValue }
/>
</BaseControl.VisualLabel>
</div>
</legend>
<VStack spacing={ 1 }>
{ showTitle && (
<legend>
<div className="block-editor-color-gradient-control__color-indicator">
<BaseControl.VisualLabel>
{ label }
</BaseControl.VisualLabel>
</div>
</legend>
) }
{ canChooseAColor && canChooseAGradient && (
<ToggleGroupControl
value={ currentTab }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export const PanelColorGradientSettingsInner = ( {
>
{ settings.map( ( setting, index ) => (
<ColorGradientControl
showTitle={ showTitle }
key={ index }
{ ...{
colors,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ import { noop } from 'lodash';
*/
import ColorGradientControl from '../control';

const getButtonWithTestPredicate = ( text ) => ( element ) => {
return (
element.type === 'button' &&
element.children[ 0 ] === text &&
element.children.length === 1
);
};

const getButtonWithAriaLabelStartPredicate = ( ariaLabelStart ) => (
element
) => {
Expand Down Expand Up @@ -76,9 +68,6 @@ describe( 'ColorPaletteControl', () => {

// Is showing the two predefined Colors.
expect( screen.getAllByLabelText( /^Color:/ ) ).toHaveLength( 2 );

// Is showing the custom color picker.
expect( screen.queryByText( 'Custom color' ) ).toBeInTheDocument();
} );

it( 'renders the color picker and does not render tabs if it is only possible to select a color', async () => {
Expand Down Expand Up @@ -116,11 +105,6 @@ describe( 'ColorPaletteControl', () => {
getButtonWithAriaLabelStartPredicate( 'Color:' )
)
).toHaveLength( 2 );

// Is showing the custom color picker.
expect(
wrapper.root.findAll( getButtonWithTestPredicate( 'Custom color' ) )
).toHaveLength( 1 );
} );

it( 'renders the gradient picker and does not render tabs if it is only possible to select a gradient', async () => {
Expand Down
Loading