- {views}
- {!views.length &&
}
+
+
+
+ {views}
+ {!views.length && }
+
+ {hoveredOption?.[selectInfoKey] && (
+
+
{hoveredOption.label || hoveredOption.value}
+
{hoveredOption?.[selectInfoKey]}
+
+ )}
);
diff --git a/src/components/select/views/selected.js b/src/components/select/views/selected.js
index 4a8aea42..5ad23893 100644
--- a/src/components/select/views/selected.js
+++ b/src/components/select/views/selected.js
@@ -99,6 +99,7 @@ export default class Selected extends React.Component {
selectAllText,
borderRadiusSize,
scrollSelected,
+ selectInfoKey,
},
state: { selectedList, clear },
onMouseEnter,
@@ -170,6 +171,7 @@ export default class Selected extends React.Component {
optionRender={optionRender}
selectAllText={selectAllText}
scrollSelected={scrollSelected}
+ selectInfoKey={selectInfoKey}
/>
diff --git a/src/components/tooltip/index.js b/src/components/tooltip/index.js
index 56973a57..e7d41b58 100644
--- a/src/components/tooltip/index.js
+++ b/src/components/tooltip/index.js
@@ -214,6 +214,20 @@ Tooltip.propTypes = {
`${CONFIG_PLACE.right}-${CONFIG_PLACE.top}`,
`${CONFIG_PLACE.right}-${CONFIG_PLACE.bottom}`,
]),
+ defaultPlacement: PropTypes.oneOf([
+ CONFIG_PLACE.top,
+ `${CONFIG_PLACE.top}-${CONFIG_PLACE.left}`,
+ `${CONFIG_PLACE.top}-${CONFIG_PLACE.right}`,
+ CONFIG_PLACE.bottom,
+ `${CONFIG_PLACE.bottom}-${CONFIG_PLACE.left}`,
+ `${CONFIG_PLACE.bottom}-${CONFIG_PLACE.right}`,
+ CONFIG_PLACE.left,
+ `${CONFIG_PLACE.left}-${CONFIG_PLACE.top}`,
+ `${CONFIG_PLACE.left}-${CONFIG_PLACE.bottom}`,
+ CONFIG_PLACE.right,
+ `${CONFIG_PLACE.right}-${CONFIG_PLACE.top}`,
+ `${CONFIG_PLACE.right}-${CONFIG_PLACE.bottom}`,
+ ]),
theme: PropTypes.oneOf([
CONFIG_THEME.dark,
CONFIG_THEME.light,
@@ -237,6 +251,7 @@ Tooltip.defaultProps = {
trigger: 'hover',
visible: undefined,
placement: CONFIG_PLACE.auto,
+ defaultPlacement: CONFIG_PLACE.top,
theme: CONFIG_THEME.dark,
className: '',
overlayStyle: {},
diff --git a/src/components/tooltip/index.md b/src/components/tooltip/index.md
index 08860d76..2ae49545 100644
--- a/src/components/tooltip/index.md
+++ b/src/components/tooltip/index.md
@@ -17,23 +17,24 @@ group:
### API
-| 参数 | 说明 | 类型 | 默认值 |
-| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------- | ------------- |
-| content | 内容(可以为任意一段 html 内容) | string | |
-| theme | 主题, 可选 `dark` `light` `error` | string | dark |
-| trigger | 触发方式 `hover` `click` | string | hover |
-| visible | 用于手动控制浮层显隐 | boolean | undefined |
-| control | 配置成 true,结合 visible 使用,实现手动控制浮层显隐 | boolean | false |
-| onVisibleChange | 显示隐藏的回调 | (visible: boolean) => void | () => {} |
-| container |
渲染节点,默认渲染到 body 上(如果指定容器,将会给指定容器添加 position:relative),已废弃 | function | document.body |
-| mouseEnterDelay | 鼠标移入后延时多少才显示 Tooltip,单位:毫秒 | number | 1 |
-| mouseLeaveDelay | 鼠标移出后延时多少才隐藏 Tooltip,单位:毫秒 | number | 1 |
-| placement | 气泡框位置,可选 `auto` `top` `left` `right` `bottom` `top-left` `top-right` `bottom-left` `bottom-right` `left-top` `left-bottom` `right-top` `right-bottom` | string | auto |
-| className | 设置类样式 | string | '' |
-| overlayStyle | 自定义卡片样式 | object | {} |
-| alwaysShow | 设置 visible 为 true 后,点击其他位置,tooltip 不消失 | bool | false |
-| showArrow | 配置箭头的显隐,默认为 true | bool | false |
-| scrollContainer | 设置滚动根节点, 代码根据此根节点计算提示语的偏移量 | DOM | document.body |
+| 参数 | 说明 | 类型 | 默认值 |
+| ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------- | ------------- |
+| content | 内容(可以为任意一段 html 内容) | string | |
+| theme | 主题, 可选 `dark` `light` `error` | string | dark |
+| trigger | 触发方式 `hover` `click` | string | hover |
+| visible | 用于手动控制浮层显隐 | boolean | undefined |
+| control | 配置成 true,结合 visible 使用,实现手动控制浮层显隐 | boolean | false |
+| onVisibleChange | 显示隐藏的回调 | (visible: boolean) => void | () => {} |
+| container |
渲染节点,默认渲染到 body 上(如果指定容器,将会给指定容器添加 position:relative),已废弃 | function | document.body |
+| mouseEnterDelay | 鼠标移入后延时多少才显示 Tooltip,单位:毫秒 | number | 1 |
+| mouseLeaveDelay | 鼠标移出后延时多少才隐藏 Tooltip,单位:毫秒 | number | 1 |
+| placement | 气泡框位置,可选 `auto` `top` `left` `right` `bottom` `top-left` `top-right` `bottom-left` `bottom-right` `left-top` `left-bottom` `right-top` `right-bottom` | string | auto |
+| defaultPlacement | placement 设置为 `auto` 时候,气泡框默认位置,可选 `top` `left` `right` `bottom` `top-left` `top-right` `bottom-left` `bottom-right` `left-top` `left-bottom` `right-top` `right-bottom` | string | auto |
+| className | 设置类样式 | string | '' |
+| overlayStyle | 自定义卡片样式 | object | {} |
+| alwaysShow | 设置 visible 为 true 后,点击其他位置,tooltip 不消失 | bool | false |
+| showArrow | 配置箭头的显隐,默认为 true | bool | false |
+| scrollContainer | 设置滚动根节点, 代码根据此根节点计算提示语的偏移量 | DOM | document.body |
### 代码演示
diff --git a/src/components/tooltip/toolView.js b/src/components/tooltip/toolView.js
index 1338005c..1db5c2c2 100644
--- a/src/components/tooltip/toolView.js
+++ b/src/components/tooltip/toolView.js
@@ -49,12 +49,14 @@ function getScrollOffset(ele, scrollContainer = document.body, type) {
}
// 获取方向
-function getDirection(tooltip, target, placement) {
+function getDirection(tooltip, target, placement, defaultPlacement = CONFIG_PLACE.top) {
const { top, left } = getAbsPosition(target);
const targetRect = target.getBoundingClientRect();
- let main = 'top';
- let vice = 'center';
+ const [p1, p2] = defaultPlacement?.split('-')
+
+ let main = p1 || 'top';
+ let vice = p2 || 'center';
if (placement === 'auto') {
if (top - tooltip.offsetHeight < top - targetRect.top) {
@@ -78,12 +80,13 @@ export function getTooltipPositionInBody(
target,
placement,
scrollContainer,
+ defaultPlacement = CONFIG_PLACE.top,
) {
const { offsetWidth, offsetHeight } = tooltip;
const { left, top, right, bottom, width, height } = getAbsPosition(target);
const style = {};
- const [main, vice] = getDirection(tooltip, target, placement);
+ const [main, vice] = getDirection(tooltip, target, placement, defaultPlacement);
switch (main) {
case CONFIG_PLACE.top:
@@ -144,7 +147,7 @@ export default class ToolView extends Component {
timer = null;
componentDidMount() {
- const { placement, target, scrollContainer } = this.props;
+ const { placement, defaultPlacement, target, scrollContainer } = this.props;
const tooltip = this.tipRef.current;
setTimeout(() => {
@@ -155,8 +158,9 @@ export default class ToolView extends Component {
target,
placement,
scrollContainer,
+ defaultPlacement,
),
- dir: getDirection(tooltip, target, placement).join('-'),
+ dir: getDirection(tooltip, target, placement, defaultPlacement).join('-'),
},
() => this.setState({ show: true }),
);