Skip to content

Commit

Permalink
DataViews: update renderFormElements to make sure the value respect…
Browse files Browse the repository at this point in the history
…s the type (#64391)

Co-authored-by: oandregal <oandregal@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
  • Loading branch information
3 people authored Aug 9, 2024
1 parent 02622ae commit 360c6f9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/dataviews/src/field-types/integer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function Edit< Item >( {
( newValue: string | undefined ) =>
onChange( ( prevItem: Item ) => ( {
...prevItem,
[ id ]: newValue,
[ id ]: Number( newValue ),
} ) ),
[ id, onChange ]
);
Expand Down
11 changes: 4 additions & 7 deletions packages/dataviews/src/normalize-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,10 @@ export function normalizeFields< Item >(

const renderFromElements = ( { item }: { item: Item } ) => {
const value = getValue( { item } );
const label = field?.elements?.find( ( element ) => {
// Intentionally using == here to allow for type coercion.
// eslint-disable-next-line eqeqeq
return element.value == value;
} )?.label;

return label || value;
return (
field?.elements?.find( ( element ) => element.value === value )
?.label || getValue( { item } )
);
};

const render =
Expand Down

0 comments on commit 360c6f9

Please sign in to comment.