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.

Get width of <Box>

See original GitHub issue

Is it possible to obtain the width of the Box element in Ink 2.0?

Issue Analytics

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

github_iconTop GitHub Comments

5reactions
vadimdemedescommented, Apr 15, 2019

I’m thinking about measureElement method that Ink could expose that would allow you to measure any element after component is mounted. For example:

import {measureElement} from 'ink';

class Hello extends React.Component {
  constructor() {
    super()

    this.elementRef = React.createRef()
  }

  render() {
    return (
      <SomeElement ref={this.elementRef}/>
    )
  }

  componentDidMount() {
    const dimensions = measureElement(this.elementRef)
    //=> { width: 40, height: 20 }
  }
}

What do you think?

1reaction
jdeniaucommented, Apr 15, 2019

It does seems to work, but it seems to be not that used in the React ecosystem, isn’t it ?

Moreover, it may be difficult to react to a size change (if you resize your terminal for example).

Another solution might to expose a onDimensionChanged callback on Box, that is called on first rendering and when the box dimension did change, but I’m not really happy with this either ^^

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting Width & Height of an Element in JavaScript
In this tutorial, you will learn how to get the current computed dimension of an element, including width and height, in JavaScript.
Read more >
JavaScript get size of content box - dom - Stack Overflow
I need a way to get the size of the content box width and hight in pixels. I'm open to work around's like...
Read more >
How to Measure the Length x Width x Height of Shipping Boxes
1. Measure the longest side of the package. Start by identifying the longest side of the package, then hold a ruler or tape...
Read more >
box-sizing - CSS: Cascading Style Sheets - MDN Web Docs
The box-sizing CSS property sets how the total width and height of an element is calculated.
Read more >
How to Measure Dimensions of a Box - PakFactory Blog
The Three Dimensions of a Box · Length: The longest side when looking at the top of the box. · Width: The shorter...
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