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

Add selected attribute for radio and select controls #3534

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion blocks/inspector-controls/radio-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function RadioControl( { label, selected, help, instanceId, onChange, options =
name={ id }
value={ option.value }
onChange={ onChangeValue }
selected={ option.value === selected }
defaultChecked={ option.value === selected }
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need this change? we're using "value" to make the radio control "controllable". Same for the select one.

aria-describedby={ !! help ? id + '__help' : undefined }
/>
<label key={ option.value } htmlFor={ ( id + '-' + index ) }>
Expand Down
3 changes: 2 additions & 1 deletion blocks/inspector-controls/select-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { withInstanceId } from '@wordpress/components';
import BaseControl from './../base-control';
import './style.scss';

function SelectControl( { label, help, instanceId, onChange, options = [], ...props } ) {
function SelectControl( { label, selected, help, instanceId, onChange, options = [], ...props } ) {
const id = 'inspector-select-control-' + instanceId;
const onChangeValue = ( event ) => onChange( event.target.value );

Expand All @@ -28,6 +28,7 @@ function SelectControl( { label, help, instanceId, onChange, options = [], ...pr
className="blocks-select-control__input"
onChange={ onChangeValue }
aria-describedby={ !! help ? id + '__help' : undefined }
defaultValue={ selected }
{ ...props }
>
{ options.map( ( option ) =>
Expand Down