question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Removing borderTopWidth does not work

See original GitHub issue

Do you want to request a feature or report a bug? I want to report a bug.

What is the current behavior?

export default class App extends React.Component {
  state = {
    toggled: true,
    style: {
      border: "10px solid black"
    }
  };
  handleClick = () => {
    console.log("clicked");
    const style = { ...this.state.style };
    if (this.state.toggled) {
      style.borderTopWidth = 0;
    } else {
      delete style.borderTopWidth; // BUG: removing borderTopWidth does not work
    }
    this.setState({
      style,
      toggled: !this.state.toggled
    });
  };
  render() {
    const style = this.state.style;
    return (
      <div className="App" style={style}>
        <h1>Hello CodeSandbox</h1>
        <h2>Start editing to see some magic happen!</h2>
        <button onClick={this.handleClick}>button</button>
      </div>
    );
  }
}

test

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn’t have dependencies other than React. Paste the link to your JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new) example below: https://codesandbox.io/s/34m3njok6p What is the expected behavior? Top border should be set back to 10px after deleting borderTopWidth.

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React? React 16.5.2 Mac Sierra 10.12.6 Version 69.0.3497.100 (Official Build)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
awearycommented, Oct 22, 2018

This looks like the native behavior for setting/overriding border style values.

If you use the border shorthand, and then override it by setting a more specific value (like borderTopWidth) it expands the shorthand and explicitly uses each border property. Then when you try and override it again, it doesn’t work because the properties have already been expanded.

I’m sure this is defined somewhere in the spec, and I’m not sure if there’s anything React can do here to easily fix this.

0reactions
picodothcommented, Oct 23, 2018

@aweary Thanks for your response, closing this issue then!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I remove "border-top-width" css style? - Stack Overflow
CSS proposes an initial value which would reset it to the default value for the browser. There is no way (and no proposed...
Read more >
border-top-width - CSS: Cascading Style Sheets | MDN
The border-top-width CSS property sets the width of the top border of an element.
Read more >
border top/left/bottom/right width not working · Issue #29 - GitHub
But if I change the borderWidth in the first component to borderBottomWidth or any of the other top/left/bottom/right methods, there is no border....
Read more >
Border Width - Tailwind CSS
Utilities for controlling the width of an element's borders.
Read more >
CSS border-top-width Property - W3docs
The border-top-width property is used for defining the width of the top border of an element. See all property values illustrated with examples....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found