Skip to content

@ionic/react bug: className overrides classes instead of concats #18137

Closed

Description

@Kikketer

Bug Report

Ionic version:

[x] 4.x

Current behavior:
For the React Ionic app, adding a className to a component may work on initial load but after any interaction it does not gain the needed classes provided by Ionic.

For example if you use styled-components or simply set a className to a component (say toolbar):

<IonToolbar className="my-custom-header">

or

const StyledToolbar = styled(IonToolbar)`
  --background: orange;
`
...
<StyledToolbar>

This results in:

<ion-toolbar classname="sc-bdVaJa gYsGnC" class="sc-bdVaJa gYsGnC ios hydrated">

but after interaction the ios and hydrated classes are lost:

<ion-toolbar classname="sc-bdVaJa gYsGnC" class="sc-bdVaJa gYsGnC">

The color will apply on initial render but fail after any sort of change to the app, like navigating to the next screen.

Expected behavior:
className should be appended to any needed classes built in to Ionic. This would allow the use of CSS-in-JS which is becoming more and more common. Also with some apps (like the one I'm working on) we need to easily set variables via a network retrieved file that contains colors and other customizations.

Steps to reproduce:
Easiest way to reproduce is to create a css class and attach it to something like the <IonToolbar>:

css:

.my-custom-class {
  --background: orange;
}

jsx:

<IonToolbar className="my-custom-class">

Related code:

I have an example using styled-components here:
https://github.com/Kikketer/ionic-react-bugger/blob/styled-components/src/FirstPage.js#L6

And one using a simple className here:
https://github.com/Kikketer/ionic-react-bugger/blob/styled-components/src/SecondPage.js#L9

Other information:

Ionic info:

Ionic:

   ionic (Ionic CLI) : 4.12.0

System:

   NodeJS : v11.14.0
   npm    : 6.9.0
   OS     : macOS Mojave

Activity

  1. added
    package: react
    and removed
    package: react
    on Apr 29, 2019
  2. silentHoo commented on May 2, 2019

    @silentHoo

    @Kikketer You can workaround that issue by using class instead of className.

    This is what the official react docs suggest:

    One common confusion is that Web Components use “class” instead of “className”.

    function BrickFlipbox() {
     return (
       <brick-flipbox class="demo">
         <div>front</div>
         <div>back</div>
       </brick-flipbox>
     );
    }
    

    https://reactjs.org/docs/web-components.html#using-web-components-in-react

    Here's a similar issue reported: #17962

  3. elylucas commented on May 8, 2019

    @elylucas
    Contributor

    Fixed in #18231. Thanks!

  4. ionitron-bot commented on Jun 7, 2019

    @ionitron-bot

    Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

  5. locked and limited conversation to collaborators on Jun 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    package: react

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions