Skip to content

Commit

Permalink
Components: Try fixing the active state of toolbar SVG icons on nativ…
Browse files Browse the repository at this point in the history
…e mobile
  • Loading branch information
gziolo committed Oct 3, 2019
1 parent 0bef434 commit 4eb89cc
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 15 deletions.
4 changes: 2 additions & 2 deletions packages/block-library/src/image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ export class ImageEdit extends Component {
<IconButton
className={ classnames( 'components-icon-button components-toolbar__control', { 'is-active': this.state.isEditing } ) }
label={ __( 'Edit image' ) }
aria-pressed={ this.state.isEditing }
isToggled={ this.state.isEditing }
onClick={ this.toggleIsEditing }
icon={ editImageIcon }
/>
Expand Down Expand Up @@ -747,7 +747,7 @@ export class ImageEdit extends Component {
key={ scale }
isSmall
isPrimary={ isCurrent }
aria-pressed={ isCurrent }
isToggled={ isCurrent }
onClick={ this.updateDimensions( scaledWidth, scaledHeight ) }
>
{ scale }%
Expand Down
4 changes: 3 additions & 1 deletion packages/components/src/button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ export function Button( props, ref ) {
} );

const tag = href !== undefined && ! disabled ? 'a' : 'button';
const tagProps = tag === 'a' ? { href, target } : { type: 'button', disabled };
const tagProps = tag === 'a' ?
{ href, target } :
{ type: 'button', disabled, 'aria-pressed': isToggled };

return createElement( tag, {
...tagProps,
Expand Down
10 changes: 5 additions & 5 deletions packages/components/src/button/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ export function Button( props ) {
hint,
fixedRatio = true,
getStylesFromColorScheme,
isToggled,
'aria-disabled': ariaDisabled,
'aria-label': ariaLabel,
'aria-pressed': ariaPressed,
'data-subscript': subscript,
} = props;

Expand All @@ -79,11 +79,11 @@ export function Button( props ) {
const buttonViewStyle = {
opacity: isDisabled ? 0.3 : 1,
...( fixedRatio && styles.fixedRatio ),
...( ariaPressed ? styles.buttonActive : styles.buttonInactive ),
...( isToggled ? styles.buttonActive : styles.buttonInactive ),
};

const states = [];
if ( ariaPressed ) {
if ( isToggled ) {
states.push( 'selected' );
}

Expand All @@ -94,7 +94,7 @@ export function Button( props ) {
const subscriptInactive = getStylesFromColorScheme( styles.subscriptInactive, styles.subscriptInactiveDark );

const newChildren = Children.map( compact( children ), ( child ) => {
return cloneElement( child, { colorScheme: props.preferredColorScheme, active: ariaPressed } );
return cloneElement( child, { colorScheme: props.preferredColorScheme, active: isToggled } );
} );

return (
Expand All @@ -112,7 +112,7 @@ export function Button( props ) {
<View style={ buttonViewStyle }>
<View style={ { flexDirection: 'row' } }>
{ newChildren }
{ subscript && ( <Text style={ ariaPressed ? styles.subscriptActive : subscriptInactive }>{ subscript }</Text> ) }
{ subscript && ( <Text style={ isToggled ? styles.subscriptActive : subscriptInactive }>{ subscript }</Text> ) }
</View>
</View>
</TouchableOpacity>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,6 @@ exports[`TimePicker matches the snapshot when the is12hour prop is specified 1`]
className="components-datetime__time-field components-datetime__time-field-am-pm"
>
<ForwardRef(Button)
aria-pressed={false}
className="components-datetime__time-am-button"
isDefault={true}
isToggled={false}
Expand All @@ -330,7 +329,6 @@ exports[`TimePicker matches the snapshot when the is12hour prop is specified 1`]
AM
</ForwardRef(Button)>
<ForwardRef(Button)
aria-pressed={true}
className="components-datetime__time-pm-button"
isDefault={true}
isToggled={true}
Expand Down Expand Up @@ -504,7 +502,6 @@ exports[`TimePicker matches the snapshot when the is12hour prop is true 1`] = `
className="components-datetime__time-field components-datetime__time-field-am-pm"
>
<ForwardRef(Button)
aria-pressed={false}
className="components-datetime__time-am-button"
isDefault={true}
isToggled={false}
Expand All @@ -513,7 +510,6 @@ exports[`TimePicker matches the snapshot when the is12hour prop is true 1`] = `
AM
</ForwardRef(Button)>
<ForwardRef(Button)
aria-pressed={true}
className="components-datetime__time-pm-button"
isDefault={true}
isToggled={true}
Expand Down
2 changes: 0 additions & 2 deletions packages/components/src/date-time/time.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@ class TimePicker extends Component {
{ is12Hour && (
<div className="components-datetime__time-field components-datetime__time-field-am-pm">
<Button
aria-pressed={ am === 'AM' }
isDefault
className="components-datetime__time-am-button"
isToggled={ am === 'AM' }
Expand All @@ -310,7 +309,6 @@ class TimePicker extends Component {
{ __( 'AM' ) }
</Button>
<Button
aria-pressed={ am === 'PM' }
isDefault
className="components-datetime__time-pm-button"
isToggled={ am === 'PM' }
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/toolbar-button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function ToolbarButton( {
className,
{ 'is-active': isActive }
) }
aria-pressed={ isActive }
isToggled={ isActive }
disabled={ isDisabled }
{ ...extraProps }
/>
Expand Down

0 comments on commit 4eb89cc

Please sign in to comment.