linaria icon indicating copy to clipboard operation
linaria copied to clipboard

Provide an option to disable props filtering

Open Chen-jj opened this issue 2 years ago • 5 comments

Describe the enhancement

Provide an option to disable props filtering.

Motivation

Now, there is a filter for props:

https://github.com/callstack/linaria/blob/master/packages/react/src/styled.ts#L111-L120

But the conditions for checking whether an element is HTML tag or custom element are not satisfy with our cases.

We have some element with names like: ViewTextInput from WeChat MiniApp,and both of them have some special attributes like: hoverClass.Once linaria filter these attributes, then it will not work correctly.

WeChat MiniApp' docs

Possible implementations

// Check if it's an HTML tag and not a custom element
if (options.enablePropsFilter && typeof component === 'string' && component.indexOf('-') === -1) {
  // ...
} else {
  filteredProps = rest;
}

Chen-jj avatar May 09 '22 11:05 Chen-jj

Hi @Chen-jj! Unfortunately, there is no clear way to pass such an option to styled. However, there are no built-in components that start with a capital letter, so will it be enough for you if I add a check that will ignore all components that start with a capital?

Anber avatar May 13 '22 08:05 Anber

Fixed in #970

Anber avatar May 13 '22 09:05 Anber

@Anber Thanks for fixing it.However, we use styled('view') in that case, because it refers to a built-in component with React.createElement.According to your PR, we can use styled('View'), but could you please change to lowercase for us before passing to React.createElement?Otherwise, React will refers to a user-defined component and throw an error.

Chen-jj avatar May 16 '22 03:05 Chen-jj

@Chen-jj Unfortunately, it seems like there is no way to detect whether or not passed argument is a default tag or a custom component. According to the specs, names of custom components must have a hyphen, so View and especially view are just wrong names and we cannot support them.

Anber avatar May 29 '22 07:05 Anber

Ok, I have an idea, but I need some time to implement it.

Anber avatar May 29 '22 14:05 Anber