如何仅使 React bootstrap table header 的文本可点击

How to make only text of react bootstrap table header clickable

代码:

<TableHeaderColumn dataField="test" isKey dataSort>Column</TableHeaderColumn>

有了这个列的整个区域都可以点击,我只希望文本和 V 形图标可以点击,我该如何实现。

This image show that the whole area is clickable

请帮忙,我被卡住了

This is the output HTML generated

您可以使用 css 来禁止点击使用 pointer-events 的某些元素 属性:

pointer-events: none;

这是 属性 的 none 值的定义:

none: The element is never the target of mouse events; however, mouse events may target its descendant elements if those descendants have pointer-events set to some other value. In these circumstances, mouse events will trigger event listeners on this parent element as appropriate on their way to/from the descendant during the event capture/bubble phases.

似乎 TableHeaderColumn 生成了一些具有特定 class 的 html,像这样:

 <th class="sort-column">

你可以写 css:

 .sort-column{
 pointer-events:none;

}

禁止点击整列,但由于这也会禁止点击文本,因此您需要重置指针事件 属性 关闭子元素(文本)

 .sort-column-child{
   pointer-events:auto;
 }

您将如何使用它:

   <TableHeaderColumn dataField="test" isKey dataSort><span class="sort-column-child">Column</span></TableHeaderColumn>