Skip to content

Commit

Permalink
Merge pull request #6878 from alibaba/feat/rax_compat_props_lowercase
Browse files Browse the repository at this point in the history
Compat for legacy camelcase props
  • Loading branch information
linbudu599 authored May 21, 2024
2 parents 570205a + 065e68d commit a31c5eb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/gold-scissors-know.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'rax-compat': patch
---

lowercase props compat
1 change: 1 addition & 0 deletions packages/rax-compat/src/possible-standard-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const possibleStandardNames = [
'marginHeight',
// meta
'charSet',
'dangerouslySetInnerHTML',
].reduce((records: Record<string, string>, iter: string) => {
records[iter.toLowerCase()] = iter;
return records;
Expand Down
3 changes: 3 additions & 0 deletions packages/rax-compat/src/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ function transformProps(props: ComponentProps<JSXElementConstructor<any>>): Reco
} else if (possibleStandardNames.hasOwnProperty(lowerCasedPropKey)) {
// Transform attribute names that make it works properly in React.
key = possibleStandardNames[lowerCasedPropKey];
} else {
// Handles component props from rax-components like resizeMode, this causes React to throw a warning.
key = lowerCasedPropKey;
}

transformedProps[key] = val;
Expand Down
10 changes: 10 additions & 0 deletions packages/rax-compat/tests/props.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,14 @@ describe('props', () => {
inputmode: 'numeric',
}).inputMode).toBe('numeric');
});

it('should work with dangerouslySetInnerHTML', () => {
expect(
transformProps({
dangerouslySetInnerHTML: { __html: 'xxx' },
}).dangerouslySetInnerHTML,
).toEqual({
__html: 'xxx',
});
});
});

0 comments on commit a31c5eb

Please sign in to comment.