Skip to content

Commit e11444e

Browse files
authored
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
1 parent 6c3ec4f commit e11444e

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/createSliderWithTooltip.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ export default function createSliderWithTooltip(Component) {
99
tipFormatter: PropTypes.func,
1010
handleStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.arrayOf(PropTypes.object)]),
1111
tipProps: PropTypes.object,
12+
getTooltipContainer: PropTypes.func,
1213
};
1314
static defaultProps = {
1415
tipFormatter(value) { return value; },
1516
handleStyle: [{}],
1617
tipProps: {},
18+
getTooltipContainer: node => node.parentNode,
1719
};
1820
state = {
1921
visibles: {},
@@ -33,6 +35,7 @@ export default function createSliderWithTooltip(Component) {
3335
tipFormatter,
3436
tipProps,
3537
handleStyle,
38+
getTooltipContainer,
3639
} = this.props;
3740

3841
const {
@@ -53,6 +56,7 @@ export default function createSliderWithTooltip(Component) {
5356
return (
5457
<Tooltip
5558
{...restTooltipProps}
59+
getTooltipContainer={getTooltipContainer}
5660
prefixCls={prefixCls}
5761
overlay={overlay}
5862
placement={placement}

tests/common/createSlider.test.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable max-len, no-undef */
22
import React from 'react';
33
import { mount } from 'enzyme';
4-
import Slider, { Range } from '../../src';
4+
import Slider, { Range, createSliderWithTooltip } from '../../src';
55

66
const setWidth = (object, width) => {
77
// https://github.com/tmpvar/jsdom/commit/0cdb2efcc69b6672dc2928644fc0172df5521176
@@ -269,4 +269,17 @@ describe('createSlider', () => {
269269
expect(sliderOnAfterChange).toHaveBeenCalled();
270270
expect(sliderOnAfterChange).toHaveBeenCalledTimes(1);
271271
});
272+
273+
it('the tooltip should be attach to the container with the id tooltip', () => {
274+
const SliderWithTooltip = createSliderWithTooltip(Slider);
275+
const tooltipPrefixer = {
276+
prefixCls: 'slider-tooltip',
277+
};
278+
const tooltipParent = document.createElement('div');
279+
tooltipParent.setAttribute('id', 'tooltip');
280+
const wrapper = mount(
281+
<SliderWithTooltip tipProps={tooltipPrefixer} getTooltipContainer={() => document.getElementById('tooltip')} />
282+
);
283+
expect(wrapper.instance().props.getTooltipContainer).toBeTruthy();
284+
});
272285
});

0 commit comments

Comments
 (0)