Skip to content

Commit

Permalink
feat(rax-compat): lowercase props compat
Browse files Browse the repository at this point in the history
  • Loading branch information
linbudu599 committed May 6, 2024
1 parent 7bd238a commit 60ed0e1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 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
20 changes: 12 additions & 8 deletions packages/rax-compat/src/possible-standard-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@ const possibleStandardNames = [
'marginHeight',
// meta
'charSet',
].reduce((records: Record<string, string>, iter: string) => {
records[iter.toLowerCase()] = iter;
return records;
}, {
// Special cases.
class: 'className',
for: 'htmlFor',
});
'dangerouslySetInnerHTML',
].reduce(
(records: Record<string, string>, iter: string) => {
records[iter.toLowerCase()] = iter;
return records;
},
{
// Special cases.
class: 'className',
for: 'htmlFor',
},
);

export default possibleStandardNames;
4 changes: 4 additions & 0 deletions packages/rax-compat/src/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ 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;
val = typeof val === 'boolean' ? val.toString() : val;
}

transformedProps[key] = val;
Expand Down

0 comments on commit 60ed0e1

Please sign in to comment.