2

I'm building a ReactJS grid component that will allow me to resize its width. The resize is done by clicking on the grip div of the component and dragging it left or right. My code:

class Cell extends Component {

  handleGrip = event => {
    if (this.props.onGrip) this.props.onGrip(event);
  };

  render() {
    let gripComponent = (
      <div
        onMouseDown={this.handleGrip}
        className="cell-grip"
      />
    );

    let width = this.props.width;

    return (
      <div
        className={"cell-container"}
        style={{ width: width }}
      >
        <div className="cell-content">{this.props.children}</div>
        {gripComponent}
      </div>
    );
  }
}

export default Cell;

SCSS Class:

.cell-container {
    width: 100%;
    border: 1px solid $ux-theme-color-border;
    margin: 0 -1px 0 0;
    background-color: $ux-theme-color-white;
    display: flex;
    flex-direction: row;
}

.cell-content {
    flex-shrink: 1;
    width: 100%;
    padding: 5px;
    font-size: 12px;
}

.cell-grip {
    flex-shrink: 0;
    width: 5px;
    min-width: 5px;
    cursor: ew-resize;
    background-color: $ux-theme-color-border;
}

(The full widht calculation and event handling is not shown here)

All working fine, except for one thing. The grip component is rendered in a flexbox right positioned to its content. When the width gets to small, the grip is not rendered and therefore I cannot select it any more. This causes me to be unable to resize the cell if it gets too small, as there is no grip shown to select. Check images before and after:

Before:

Before

After resize:

After

The grip disappear once the width of the cell gets smaller than the width of the content (cell-content) (first flex item do show).

How can I prevent this to happen and guarantee that the grip will be shown on any width?

Mendes
  • 17,489
  • 35
  • 150
  • 263
  • Are you able to reproduce the problem in jsfiddle / codepen? Do any answers here help? https://stackoverflow.com/q/39765052/3597276 – Michael Benjamin Apr 17 '19 at 19:51

0 Answers0