Skip to content

Commit de2b8ee

Browse files
Fix incorrect edge detection logic.
It looks like previously `.indexOf !== region` should have been `.indexOf(region) !== -1`. Since incorrect edge flipping to the point of UI breakage doesn't happen that often this went undetected for quite some time. So the logic is now fixed to do the right thing and does so in a way a little more performant than calling `indexOf` on a two-element constant array.
1 parent 2fb9588 commit de2b8ee

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

src/flowtip.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,12 +354,12 @@ export default class Flowtip extends Component {
354354

355355
// Edge detection - squeeze
356356
if (
357-
(['top', 'bottom'].indexOf !== region) &&
357+
(region === 'top' || region === 'bottom') &&
358358
!regionParameter.top.fits && !regionParameter.bottom.fits
359359
) {
360360
region = this.availableAndFitsIn(['left', 'right'], regionParameter);
361361
} else if (
362-
(['left', 'right'].indexOf !== region) &&
362+
(region === 'left' || region === 'right') &&
363363
!regionParameter.left.fits && !regionParameter.right.fits
364364
) {
365365
region = this.availableAndFitsIn(['top', 'bottom'], regionParameter);

test/spec/flowtip.spec.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,29 @@ describe('FlowTip', () => {
2828
);
2929
expect(component.text()).to.equal('left');
3030
});
31+
32+
it('should edge detect properly', () => {
33+
const parent = {left: 0, top: 0, width: 300, height: 300};
34+
const anchor = parent;
35+
const tail = {width: 50, height: 50};
36+
const content = {width: 150, height: 100};
37+
const region = 'top';
38+
const offset = {left: 0, top: 0};
39+
const target = {left: 150, top: 50, width: 50, height: 50};
40+
const component = shallow(
41+
<FlowTip
42+
parent={parent}
43+
anchor={anchor}
44+
tail={tail}
45+
content={content}
46+
region={region}
47+
offset={offset}
48+
target={target}
49+
children={({region}) =>
50+
<div>{region}</div>
51+
}
52+
/>
53+
);
54+
expect(component.text()).to.equal('bottom');
55+
});
3156
});

0 commit comments

Comments
 (0)