【问题标题】:How to add 'title' tag (for tooltip) in react styled components如何在反应样式的组件中添加“标题”标签(用于工具提示)
【发布时间】:2019-10-09 01:52:15
【问题描述】:

我在我的 react 应用程序中使用样式化组件 我想添加标题属性(用于工具提示) 应用于我的样式组件

我尝试使用包装器 div html 元素并在其上应用标题标签但无法做到,也尝试使用 css`` 样式的组件助手无法做到。

my styled components: (with ellipsis):
const FilterTitle = styled.div`
    display: inline-block;
    width: 100%;
    line-height: 40px;
    height: 40px;
    color: ${blackChosen};  
    font-family: Poppins;   
    font-size: 16px;    
    letter-spacing: 0.15px;  
    padding-left: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: ${props => (props.chosen) ? '500' : 'initial'};
`;

and:

<FilterTitle> I might be a long sentence shown with ... and the title tag should tooltip me</FilterTitle>

【问题讨论】:

标签: css reactjs


【解决方案1】:

&lt;FilterTitle&gt; 仍在渲染div,因此您可以将所需的任何属性直接放在该组件上,它们将被传递给 div:

<FilterTitle title="A long sentence, eh?">...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-03
    • 2012-04-04
    • 1970-01-01
    • 1970-01-01
    • 2021-03-19
    • 1970-01-01
    • 2011-09-30
    相关资源
    最近更新 更多