Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

CSS shorthand properties do not work well when styles are overwritten #237

@bmdalex

Description

@bmdalex

CSS shorthand properties do not work well when styles are overwritten

Steps

I'm using the Divider component and want to change the default CSS margin to another value.

In marginStyles.tsx, the default margin is set using marginTop and marginBottom, like this:

const dividerStyles = {
  root: (): => ({
    marginTop: pxToRem(5 + size * 7.5),
    marginBottom: pxToRem(5 + size * 7.5),
  }),
}

What I did was to overwrite the margin using margin CSS shorthand like this:

<Divider styles={{ root: { margin: 0 }}} />

Expected Result

The Divider margin is overwritten to 0.

Actual Result

The Divider margin is not overwritten. We are using shorthand margin in order to attempt that but our mechanism merges the Provider componentStyles and the component's styles JS objects together so margin property cannot override a different property (marginTop or marginBottom in our case).

To unblock the user, the correct way to override CSS margin in this case is:

<Divider styles={{ root: { marginTop: 0, marginBottom: 0 }}} />

However, this is undesirable and we should come up with better merging strategy for CSS in JS.

Version

0.5.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    vstsPaired with ticket in vsts

    Type

    No type
    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