Unverified Commit 59a532b8 authored by Tor Raswill's avatar Tor Raswill Committed by GitHub
Browse files

#5111 Set flip to true if placement is auto in OverlayTrigger.js (#5113)



* Update OverlayTrigger.js

Set flip to true if placement is auto

* Update OverlayTrigger.js

Handle auto, auto-start and auto-end placements

* Update OverlayTriggerSpec.js

Added test for flip to true of placement is auto
Co-authored-by: default avatarTor Raswill <tor.raswill@dqc.se>
parent 66614ab3
......@@ -92,6 +92,27 @@ const propTypes = {
* @private
*/
show: PropTypes.oneOf([null]),
/**
* The placement of the Overlay in relation to it's `target`.
*/
placement: PropTypes.oneOf([
'auto-start',
'auto',
'auto-end',
'top-start',
'top',
'top-end',
'right-start',
'right',
'right-end',
'bottom-end',
'bottom',
'bottom-start',
'left-end',
'left',
'left-start',
]),
};
const defaultProps = {
......@@ -106,6 +127,8 @@ function OverlayTrigger({
popperConfig = {},
defaultShow,
delay: propsDelay,
placement,
flip = placement && placement.indexOf('auto') !== -1,
...props
}) {
const triggerNodeRef = useRef(null);
......@@ -247,6 +270,8 @@ function OverlayTrigger({
show={show}
onHide={handleHide}
target={getTarget}
placement={placement}
flip={flip}
>
{overlay}
</Overlay>
......
......@@ -208,6 +208,21 @@ describe('<OverlayTrigger>', () => {
contextSpy.calledWith('value').should.be.true;
});
it('Should have flip set to true if placement is auto', () => {
const wrapper = mount(
<OverlayTrigger
overlay={<Div>test</Div>}
trigger="click"
placement="auto"
>
<button type="button">button</button>
</OverlayTrigger>,
);
wrapper.find('button').simulate('click');
expect(wrapper.update().find(Overlay).props().flip).to.equal(true);
});
describe('overlay types', () => {
[
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment