Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/createSliderWithTooltip.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Member

@afc163 afc163 Feb 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd better not since use getTooltipContainer will beak overflow hidden. #20699 is aim to compatible with origin behavior

};
state = {
visibles: {},
Expand All @@ -33,6 +35,7 @@ export default function createSliderWithTooltip(Component) {
tipFormatter,
tipProps,
handleStyle,
getTooltipContainer,
} = this.props;

const {
Expand All @@ -53,6 +56,7 @@ export default function createSliderWithTooltip(Component) {
return (
<Tooltip
{...restTooltipProps}
getTooltipContainer={getTooltipContainer}
prefixCls={prefixCls}
overlay={overlay}
placement={placement}
Expand Down
15 changes: 14 additions & 1 deletion tests/common/createSlider.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable max-len, no-undef */
import React from 'react';
import { mount } from 'enzyme';
import Slider, { Range } from '../../src';
import Slider, { Range, createSliderWithTooltip } from '../../src';

const setWidth = (object, width) => {
// https://github.com/tmpvar/jsdom/commit/0cdb2efcc69b6672dc2928644fc0172df5521176
Expand Down Expand Up @@ -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(
<SliderWithTooltip tipProps={tooltipPrefixer} getTooltipContainer={() => document.getElementById('tooltip')} />
);
expect(wrapper.instance().props.getTooltipContainer).toBeTruthy();
});
});