Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Refactor JSX element extension with custom properties to more robust …
Browse files Browse the repository at this point in the history
…way with object copy
  • Loading branch information
kmanijak committed Dec 1, 2022
1 parent b579a24 commit 418a99f
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions assets/js/blocks/rating-filter/block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -408,16 +408,23 @@ const RatingFilterBlock = ( {

const { label, value: rawValue } =
displayedResult;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore - continue pretending this label is a string. Adding method required in further processing
label.toLocaleLowerCase = () => rawValue;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore - continue pretending this label is a string. Adding method required in further processing
label.substring = (
start: number,
end: number
) => ( start === 0 && end === 1 ? label : '' );
return label;

// A label - JSX component - is extended with faked string methods to allow using JSX element as an option in FormTokenField
const extendedLabel = Object.assign(
{},
label,
{
toLocaleLowerCase: () => rawValue,
substring: (
start: number,
end: number
) =>
start === 0 && end === 1
? label
: '',
}
);
return extendedLabel;
} }
saveTransform={ formatSlug }
messages={ {
Expand Down

0 comments on commit 418a99f

Please sign in to comment.