react-data-grid icon indicating copy to clipboard operation
react-data-grid copied to clipboard

HeaderRenderer not support children

Open qiuquanwu opened this issue 3 years ago • 2 comments

Describe the bug

To Reproduce

  1. HeaderRenderer not support children

Link to code example:

<HeaderRenderer column={column} {...props} > {other ReactNodes}</HeaderRenderer >

Environment

  • react-data-grid version:<latest>

Suggest

Modify source code

export default function HeaderRenderer<R, SR>({
  column,
  sortDirection,
  priority,
  onSort,
  isCellSelected,
  children
}: HeaderRendererProps<R, SR> & { children?: React.ReactNode }) {
  if (!column.sortable) return <>{column.name}</>;

  return (
    <SortableHeaderCell
      onSort={onSort}
      sortDirection={sortDirection}
      priority={priority}
      isCellSelected={isCellSelected}
    >
      {children ? children : column.name}
    </SortableHeaderCell>
  );
}

qiuquanwu avatar Feb 22 '22 06:02 qiuquanwu

Can you describe the use case where it is helpful. column.name can be an element also, would that work?

amanmahajan7 avatar Apr 01 '22 17:04 amanmahajan7

If you really need this its easy to make a wrapper component that has HeaderRenderer + whatever else you want inside as children. I don't think it makes sense to have children be a prop because where do you put them? Above the column name? Below? Its ambiguous.

Like -

export function FilterRenderer<R, SR, T extends HTMLOrSVGElement>(
  props: HeaderRendererProps<R, SR> & {
    children: (args: { ref: React.RefObject<T>; tabIndex: number; filters: any }) => React.ReactElement;
  }
) {
  const filters = useContext(FilterContext)!;
  const { ref, tabIndex } = useFocusRef<T>(props.isCellSelected);

  return (
    <>
      <HeaderRenderer {...props} />
      <div>{props.children({ ref, tabIndex, filters })}</div>
    </>
  );
}

noah-ellman avatar Apr 19 '22 04:04 noah-ellman