【发布时间】:2020-07-16 15:40:29
【问题描述】:
我正在使用material-table 并尝试对我当前悬停的行实现高亮显示。
documentation 仅在第三个示例中为 onRowClick 操作提供颜色变化:
function SelectedRowStyling() {
const { useState } = React;
const [selectedRow, setSelectedRow] = useState(null);
return (
<MaterialTable
title="Selected Row Styling Preview"
columns={[
{ title: 'Name', field: 'name' },
{ title: 'Surname', field: 'surname' },
{ title: 'Birth Year', field: 'birthYear', type: 'numeric' },
{
title: 'Birth Place',
field: 'birthCity',
lookup: { 34: 'İstanbul', 63: 'Şanlıurfa' },
},
]}
data={[
{ name: 'Mehmet', surname: 'Baran', birthYear: 1987, birthCity: 63 },
{ name: 'Zerya Betül', surname: 'Baran', birthYear: 2017, birthCity: 34 },
]}
onRowClick={((evt, selectedRow) => setSelectedRow(selectedRow.tableData.id))}
options={{
rowStyle: rowData => ({
backgroundColor: (selectedRow === rowData.tableData.id) ? '#EEE' : '#FFF'
})
}}
/>
)
}
我在源代码中阅读了可用的props,并没有找到像onRowHover 这样的东西。尝试了一些ThemeProvider 解决方案,但没有成功,我如何通过悬停动作实现颜色变化?
【问题讨论】:
-
如果您提供 onRowClick,悬停动作也可以直接使用。
-
@Domino987 我虽然打算这样做,但提供 onRowClick 操作会导致鼠标指针变成“点击手”,而 onRowClick 没有附加任何实际操作,从而导致不良的 UI/UX 行为,用户会认为通过单击该行会发生某些事情,而实际上不会发生。
标签: reactjs material-ui material-table