Skip to content

Commit

Permalink
Merge pull request #3225 from WordPress/fix/3106-filter-nil-aria-attr…
Browse files Browse the repository at this point in the history
…ibutes

Editable: Discard ARIA props if nil
  • Loading branch information
tiny-james authored Oct 30, 2017
2 parents be8d37a + e2ce61e commit 038bd41
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions blocks/editable/aria.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,21 @@
import {
difference,
isEqual,
isNil,
keys,
pickBy,
startsWith,
} from 'lodash';

const isAriaPropName = ( name ) =>
startsWith( name, 'aria-' );

const getAriaKeys = ( props ) =>
Object.keys( props ).filter( isAriaPropName );

export const pickAriaProps = ( props ) =>
pickBy( props, ( value, key ) => isAriaPropName( key ) );
pickBy( props, ( value, key ) => isAriaPropName( key ) && ! isNil( value ) );

export const diffAriaProps = ( props, nextProps ) => {
const prevAriaKeys = getAriaKeys( props );
const nextAriaKeys = getAriaKeys( nextProps );
const prevAriaKeys = keys( pickAriaProps( props ) );
const nextAriaKeys = keys( pickAriaProps( nextProps ) );
const removedKeys = difference( prevAriaKeys, nextAriaKeys );
const updatedKeys = nextAriaKeys.filter( ( key ) =>
! isEqual( props[ key ], nextProps[ key ] ) );
Expand Down

0 comments on commit 038bd41

Please sign in to comment.