Repository navigation
Description
Cannot use styled.search to create a <search> tag. Although you can use styled("search"), however the typescript typing is wrong (got never instead of HTMLElement). And the DevTools console will report Invalid DOM property `class`. Did you mean `className`? Error Component Stack, however I never type className to class by mistaken.
Solution
Add search to here:
styled-components/packages/styled-components/src/utils/domElements.ts
Lines 87 to 99 in a21089e
| 's', | |
| 'samp', | |
| 'script', | |
| 'section', | |
| 'select', | |
| 'small', | |
| 'source', | |
| 'span', | |
| 'strong', | |
| 'style', | |
| 'sub', | |
| 'summary', | |
| 'sup', |
Change the logic for determining whether it is a custom element.
styled-components/packages/styled-components/src/models/StyledComponent.ts
Lines 186 to 192 in a21089e
| propsForElement[ | |
| // handle custom elements which React doesn't properly alias | |
| isTag(elementToBeCreated) && | |
| !domElements.has(elementToBeCreated as Extract<typeof domElements, string>) | |
| ? 'class' | |
| : 'className' | |
| ] = classString; |
The current logic just determine whether the tag is a known tag, otherwise it is a custom element tag. This is wrong, which will effect to the future native tags. The correct way is to check if the tag name has any hyphens.
It can be changed to this:
propsForElement[
// handle custom elements which React doesn't properly alias
isTag(elementToBeCreated) &&
elementToBeCreated.includes('-')
? 'class'
: 'className'
] = classString;
Activity