Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compat for legacy camelcase props #6878

Merged
merged 7 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
});
});
});
Loading