react-overlays icon indicating copy to clipboard operation
react-overlays copied to clipboard

margin on Position target causes incorrect positioning

Open timothykang opened this issue 8 years ago • 6 comments

This issue can be reproduced directly on the Position example, by changing

<Button bsStyle='primary' ref='target' onClick={this.toggle}>

to

<Button bsStyle='primary' ref='target' onClick={this.toggle} style={{marginLeft: '10px'}}>

This issue looks to be caused by the usage of dom-helpers/query/position (in utils/calculatePosition.js). dom-helpers/query/position mimics jQuery.position(), which does not account for margins.

I believe the correct course of action is to account for margins (i.e. add them to the offsets) in utils/calculatePosition.js. If the maintainers agree I'd be happy submit a PR.

timothykang avatar Dec 19 '16 22:12 timothykang

What does upstream TWBS do?

taion avatar Dec 20 '16 02:12 taion

jquery may include margins in dimension calculations... I'll have to check

jquense avatar Dec 20 '16 03:12 jquense

It looks like TWBS uses jQuery.offset() when getting and setting positions (see js/tooltip.js, lines 295 + 370).

timothykang avatar Dec 21 '16 21:12 timothykang

See #175 for a fix.

devongovett avatar Sep 21 '17 18:09 devongovett

We actually can't do this without breaking Bootstrap compatibility. Bootstrap popovers actually do apply margins and depend on them for the positioning to look right.

This is sort of why we need to pull <Position> as-is into React-Bootstrap – it's just not in general a great primitive for anything other than TWBS overlays.

taion avatar Sep 25 '17 18:09 taion

@taion unless I'm mistaken, popover margins are a seperate issue from this ticket which is talking about target element margins.

I've taken a stab at fixing the issue with target element margins, which you can see here: https://github.com/react-bootstrap/react-overlays/pull/206

Open question: should overlays be positioned inside or outside an element's margins by default? I can see a case for both options.

qrohlf avatar Sep 25 '17 18:09 qrohlf