|
|
@@ -22,6 +22,55 @@ The difference with Tooltip is that users can operate on elements on the floatin
|
|
|
import { Popover } from '@douyinfe/semi-ui';
|
|
|
```
|
|
|
|
|
|
+### Cautions
|
|
|
+
|
|
|
+Tooltip needs to apply DOM event listeners to children. If the child element is a custom component, you need to ensure that it can pass properties to the underlying DOM element
|
|
|
+
|
|
|
+At the same time, in order to calculate the positioning of the popup layer, it is necessary to obtain the real DOM elements of the children, so Tooltip supports the following types of children
|
|
|
+
|
|
|
+1. Class Component, it is not mandatory to bind ref, but you need to ensure that props can be transparently transmitted to the real DOM node
|
|
|
+2. Use the functional component wrapped by forwardRef to transparently transmit props and ref to the real DOM node in children
|
|
|
+3. Real DOM nodes, such as span, div, p...
|
|
|
+
|
|
|
+```jsx live=true noInline=true dir="column"
|
|
|
+import React, { forwardRef } from 'react';
|
|
|
+import { Popover, Space } from '@douyinfe/semi-ui';
|
|
|
+
|
|
|
+const style={ border: '2px solid var(--semi-color-border)', paddingLeft: 4, paddingRight: 4, borderRadius: 4 };
|
|
|
+
|
|
|
+// Spread the props to the underlying DOM element. binding ref
|
|
|
+const FCChildren = forwardRef((props, ref) => {
|
|
|
+ return (<span {...props} ref={ref} style={style}>Functional Component</span>);
|
|
|
+});
|
|
|
+
|
|
|
+// Spread the props to the underlying DOM element.
|
|
|
+class MyComponent extends React.Component {
|
|
|
+ render() {
|
|
|
+ return (<span {...this.props} style={style}>ClassComponent</span>);
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+const content = (<article style={{ padding: 12 }}> Hi ByteDancer, this is a popover. <br /> We have 2 lines.</article>);
|
|
|
+
|
|
|
+function Demo() {
|
|
|
+ return (
|
|
|
+ <Space>
|
|
|
+ <Popover content={content}>
|
|
|
+ <FCChildren />
|
|
|
+ </Popover>
|
|
|
+ <Popover content={content}>
|
|
|
+ <MyComponent />
|
|
|
+ </Popover>
|
|
|
+ <Popover content={content}>
|
|
|
+ <span style={style}>DOM</span>
|
|
|
+ </Popover>
|
|
|
+ </Space>
|
|
|
+ );
|
|
|
+}
|
|
|
+render(Demo);
|
|
|
+
|
|
|
+```
|
|
|
+
|
|
|
### Basic Usage
|
|
|
|
|
|
```jsx live=true
|