From e11444eaac2d20ba2e0cd199a11a3a9777ec2b40 Mon Sep 17 00:00:00 2001 From: KALrious <31030552+KALrious@users.noreply.github.com> Date: Mon, 3 Feb 2020 02:57:45 +0100 Subject: [PATCH] feat(create-slider-with-tooltip): add get container method (#615) * feat(create-slider-with-tooltip): add get container method * follow the issue #598 * add the possibility to add a get container method to fix the relative parent of the slider's tooltip * fix(create-slider-with-tooltip): default behaviour of getTooltipContainer * fix(create-slider-with-tooltip): import handle * fix(create-slider-with-tooltip): add one test * fix(create-slider-with-tooltip): dumb commit * fix(create-slider-with-tooltip): dumb commit --- src/createSliderWithTooltip.jsx | 4 ++++ tests/common/createSlider.test.js | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/createSliderWithTooltip.jsx b/src/createSliderWithTooltip.jsx index f44ba44eb..35ca45c82 100644 --- a/src/createSliderWithTooltip.jsx +++ b/src/createSliderWithTooltip.jsx @@ -9,11 +9,13 @@ export default function createSliderWithTooltip(Component) { tipFormatter: PropTypes.func, handleStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.arrayOf(PropTypes.object)]), tipProps: PropTypes.object, + getTooltipContainer: PropTypes.func, }; static defaultProps = { tipFormatter(value) { return value; }, handleStyle: [{}], tipProps: {}, + getTooltipContainer: node => node.parentNode, }; state = { visibles: {}, @@ -33,6 +35,7 @@ export default function createSliderWithTooltip(Component) { tipFormatter, tipProps, handleStyle, + getTooltipContainer, } = this.props; const { @@ -53,6 +56,7 @@ export default function createSliderWithTooltip(Component) { return ( { // https://github.com/tmpvar/jsdom/commit/0cdb2efcc69b6672dc2928644fc0172df5521176 @@ -269,4 +269,17 @@ describe('createSlider', () => { expect(sliderOnAfterChange).toHaveBeenCalled(); expect(sliderOnAfterChange).toHaveBeenCalledTimes(1); }); + + it('the tooltip should be attach to the container with the id tooltip', () => { + const SliderWithTooltip = createSliderWithTooltip(Slider); + const tooltipPrefixer = { + prefixCls: 'slider-tooltip', + }; + const tooltipParent = document.createElement('div'); + tooltipParent.setAttribute('id', 'tooltip'); + const wrapper = mount( + document.getElementById('tooltip')} /> + ); + expect(wrapper.instance().props.getTooltipContainer).toBeTruthy(); + }); });