import React, { forwardRef } from "react"; import { cl, composeEventHandlers } from "../utils/helpers"; import { isElementInteractiveTarget } from "./Table.utils"; export interface RowProps extends React.HTMLAttributes { /** * Row is selected * @default false */ selected?: boolean; /** * Shade the table row on hover. * @default true */ shadeOnHover?: boolean; /** * Click handler for row. This differs from onClick by not being called * when clicking on interactive elements within the row (buttons, links, inputs etc). * * **Warning:** This will not be accessible by keyboard! Provide an alternative way to select the row, e.g. a checkbox or a button. */ onRowClick?: (event: React.MouseEvent) => void; } export type RowType = React.ForwardRefExoticComponent< RowProps & React.RefAttributes >; export const Row: RowType = forwardRef( ( { className, selected = false, shadeOnHover = true, onClick, onRowClick, ...rest }, ref, ) => { const handleRowClick = (event: React.MouseEvent) => { if (!onRowClick) { return; } if (isElementInteractiveTarget(event.target as HTMLElement)) { return; } onRowClick(event); }; return ( ); }, ); export default Row;