Skip to content

Commit

Permalink
Font Appearance Control: Fix selectedItem downshift uncontrolled prop…
Browse files Browse the repository at this point in the history
… warning (#34721)

* Font Appearance Control: Fix selectedItem downshift uncontrolled prop warning
  • Loading branch information
andrewserong authored Sep 14, 2021
1 parent 5571694 commit 0e7c88c
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,14 @@ export default function FontAppearanceControl( props ) {
return hasFontStyles ? styleOptions() : weightOptions();
}, [ props.options ] );

// Find current selection by comparing font style & weight against options.
const currentSelection = selectOptions.find(
( option ) =>
option.style.fontStyle === fontStyle &&
option.style.fontWeight === fontWeight
);
// Find current selection by comparing font style & weight against options,
// and fall back to the Default option if there is no matching option.
const currentSelection =
selectOptions.find(
( option ) =>
option.style.fontStyle === fontStyle &&
option.style.fontWeight === fontWeight
) || selectOptions[ 0 ];

// Adjusts field label in case either styles or weights are disabled.
const getLabel = () => {
Expand Down

0 comments on commit 0e7c88c

Please sign in to comment.