Skip to content

Commit b3c904a

Browse files
committed
Customize: Use explicit labels in hue picker.
Add `for` and `id` attributes to the customizer hue picker, so labels are explicitly associated. Move picker outside of `label` element. Add `label` value for Twenty Seventeen, Twenty Nineteen, and Twenty Twenty. Props afercia, subrataemfluence, dlh, jorbin, sainathpoojary, abcd95, mleraygp, joedolson. Fixes #42078. git-svn-id: https://develop.svn.wordpress.org/trunk@60478 602fd350-edb4-49c9-b593-d223f7449a82
1 parent b441847 commit b3c904a

File tree

7 files changed

+19
-8
lines changed

7 files changed

+19
-8
lines changed

src/wp-content/themes/twentynineteen/inc/customizer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ function twentynineteen_customize_register( $wp_customize ) {
7575
$wp_customize,
7676
'primary_color_hue',
7777
array(
78+
'label' => __( 'Custom Color', 'twentynineteen' ),
7879
'description' => __( 'Apply a custom color for buttons, links, featured images, etc.', 'twentynineteen' ),
7980
'section' => 'colors',
8081
'mode' => 'hue',

src/wp-content/themes/twentynineteen/js/customize-controls.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
control.container.slideUp( 180 );
2121
}
2222
};
23-
23+
// The control-specific label is redundant because, visually, this control is part of the Color Scheme control.
24+
control.container.find( '.customize-control-title:first' ).addClass( 'screen-reader-text' );
2425
visibility();
2526
setting.bind( visibility );
2627
});

src/wp-content/themes/twentyseventeen/assets/js/customize-controls.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
control.container.slideUp( 180 );
1919
}
2020
};
21-
21+
// The control-specific label is redundant because, visually, this control is part of the Color Scheme control.
22+
control.container.find( '.customize-control-title:first' ).addClass( 'screen-reader-text' );
2223
visibility();
2324
setting.bind( visibility );
2425
});

src/wp-content/themes/twentyseventeen/inc/customizer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ function twentyseventeen_customize_register( $wp_customize ) {
7373
$wp_customize,
7474
'colorscheme_hue',
7575
array(
76+
'label' => __( 'Hue', 'twentyseventeen' ),
7677
'mode' => 'hue',
7778
'section' => 'colors',
7879
'priority' => 6,

src/wp-content/themes/twentytwenty/assets/js/customize.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
}
2323
} );
2424
}
25+
// The control-specific label is redundant because, visually, this control is part of the Color Scheme control.
26+
control.container.find( '.customize-control-title:first' ).addClass( 'screen-reader-text' );
2527
} );
2628
} );
2729
}( jQuery, wp.customize ) );

src/wp-content/themes/twentytwenty/classes/class-twentytwenty-customize.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ public static function register( $wp_customize ) {
185185
array(
186186
'section' => 'colors',
187187
'settings' => 'accent_hue',
188+
'label' => __( 'Custom Color', 'twentytwenty' ),
188189
'description' => __( 'Apply a custom color for links, buttons, featured images.', 'twentytwenty' ),
189190
'mode' => 'hue',
190191
'active_callback' => static function () use ( $wp_customize ) {

src/wp-includes/customize/class-wp-customize-color-control.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,30 +92,34 @@ public function render_content() {}
9292
*/
9393
public function content_template() {
9494
?>
95-
<# var defaultValue = '#RRGGBB', defaultValueAttr = '',
95+
<#
96+
var defaultValue = '#RRGGBB',
97+
defaultValueAttr = '',
98+
inputId = _.uniqueId( 'customize-color-control-input-' ),
9699
isHueSlider = data.mode === 'hue';
100+
97101
if ( data.defaultValue && _.isString( data.defaultValue ) && ! isHueSlider ) {
98102
if ( '#' !== data.defaultValue.substring( 0, 1 ) ) {
99103
defaultValue = '#' + data.defaultValue;
100104
} else {
101105
defaultValue = data.defaultValue;
102106
}
103107
defaultValueAttr = ' data-default-color=' + defaultValue; // Quotes added automatically.
104-
} #>
108+
}
109+
#>
105110
<# if ( data.label ) { #>
106111
<span class="customize-control-title">{{{ data.label }}}</span>
107112
<# } #>
108113
<# if ( data.description ) { #>
109114
<span class="description customize-control-description">{{{ data.description }}}</span>
110115
<# } #>
111116
<div class="customize-control-content">
112-
<label><span class="screen-reader-text">{{{ data.label }}}</span>
117+
<label for="{{ inputId }}"><span class="screen-reader-text">{{{ data.label }}}</span></label>
113118
<# if ( isHueSlider ) { #>
114-
<input class="color-picker-hue" type="text" data-type="hue" />
119+
<input id="{{ inputId }}" class="color-picker-hue" type="number" min="1" max="359" data-type="hue" />
115120
<# } else { #>
116-
<input class="color-picker-hex" type="text" maxlength="7" placeholder="{{ defaultValue }}" {{ defaultValueAttr }} />
121+
<input id="{{ inputId }}" class="color-picker-hex" type="text" maxlength="7" placeholder="{{ defaultValue }}" {{ defaultValueAttr }} />
117122
<# } #>
118-
</label>
119123
</div>
120124
<?php
121125
}

0 commit comments

Comments
 (0)