Skip to content

Commit e302de3

Browse files
committed
Update docs and add test case for 'content' prop
1 parent d58ac95 commit e302de3

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ A tooltip component. Please wrap a content which should be shown in a tooltip.
8383

8484
+ `name` *(`string`)*: A name of tooltip. This is used by `<Origin />` component.
8585
+ `place` *(`string`|`string[]`)*: A default direction of tooltip. This value can be overwritten by `<Origin />`'s `place` prop.
86-
+ `within` *(`DOM Element`)*: A DOM element which is used to restrict the position where this tooltip is placed within.
86+
+ `within` *(`DOM`)*: A DOM element which is used to restrict the position where this tooltip is placed within.
8787
+ `onHover` *(`Function`)*: A callback function to be called on mouseover at tooltip.
8888
+ `onLeave` *(`Function`)*: A callback function to be called on mouseout at tooltip.
8989

@@ -94,7 +94,7 @@ In most cases, you may use this component without any options.
9494
For advanced usage, you can override the default handlers; `onMouseEnter` and `onMouseLeave`.
9595

9696
+ `name` *(`string`|`string[]`)*: A name(s) to specify which tooltip(s) should be used.
97-
+ `content` *(`string`)*: A text content for tooltip.
97+
+ `content` *(`string`|`DOM`|`DOM[]`)*: A content for tooltip. If string, it's sanitized by [DOMPurify](https://github.com/cure53/DOMPurify).
9898
+ `place` *(`string`|`string[]`)*: A name of direction to specify a location of tooltip.
9999
+ `tagName` *(`string`)*: A tag name of wrapper element. Default is `span`.
100100
+ `delay` *(`boolean`|`number`|`string`)*: A number of duration for delay feature.

tests/feature/content.js

+26
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,32 @@ describe('Content Example', () => {
7373
});
7474
});
7575

76+
describe('HTML or DOM content', () => {
77+
it('should be worked if string HTML is passed', () => {
78+
// Mouseover
79+
const origin = firstComponent(tree, Origin.WrappedComponent, { className: 'target html' }).refs.wrapper;
80+
TestUtils.Simulate.mouseEnter(origin);
81+
82+
const tooltip = firstComponent(tree, Tooltip.WrappedComponent).refs.tooltip;
83+
assert(getStyleValue(tooltip, 'visibility') === 'visible');
84+
assert(tooltip.innerText === 'This is a html content.\nSanitized by DOMPurify.\n');
85+
assert(tooltip.innerHTML.indexOf('</script>') === -1);
86+
assert(tooltip.innerHTML.indexOf('</a>') !== -1);
87+
assert(tooltip.innerHTML.indexOf('</b>') !== -1);
88+
});
89+
90+
it('should be worked if DOM element is passed', () => {
91+
// Mouseover
92+
const origin = firstComponent(tree, Origin.WrappedComponent, { className: 'target dom' }).refs.wrapper;
93+
TestUtils.Simulate.mouseEnter(origin);
94+
95+
const tooltip = firstComponent(tree, Tooltip.WrappedComponent).refs.tooltip;
96+
assert(getStyleValue(tooltip, 'visibility') === 'visible');
97+
assert(tooltip.innerText === 'RedGreenBlue\n');
98+
assert(tooltip.innerHTML.indexOf('</span>') !== -1);
99+
});
100+
});
101+
76102
describe('continuous updating content', () => {
77103
it('should be worked', () => {
78104
// Mouseover

0 commit comments

Comments
 (0)