Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getHeadingsFromChildren forces use of string as table cell child #105

Open
8lane opened this issue Aug 17, 2021 · 4 comments
Open

getHeadingsFromChildren forces use of string as table cell child #105

8lane opened this issue Aug 17, 2021 · 4 comments

Comments

@8lane
Copy link

8lane commented Aug 17, 2021

Hi 👋

I'm upgrading to use the v2 beta version on a project and had some issues around the responsive table component. My bad If I'm doing something totally wrong but looks to me like this might be something that could be tweaked.

My table is dynamically created using the react-table library and the table cell values are rendered via a method. This used to work fine in v1, but in v2 due to the responsive changes and more specifically the getHeadingsFromChildren helper, we can no longer use anything other than a string as a child of Table.Cell.

My code:

<Table.Head>
  {headerGroups.map((headerGroup) => {
    const { ...headerGroupProps } = headerGroup.getHeaderGroupProps()
    return (
      <Table.Row {...headerGroupProps} key={headerGroupProps.key}>
        {headerGroup.headers.map((column) => {
          const { ...headerProps } = column.getHeaderProps()
          return (
            <Table.Cell
              {...headerProps}
              key={headerProps.key}
              {column.render('Header')}
            </Table.Cell>
          )
        })}
      </Table.Row>
    )
  })}
</Table.Head>

What gets rendered now:
image

I fixed this for now by importing renderToString from react-dom/server but this isn't an ideal solution

Thanks

@KaiSpencer
Copy link
Contributor

Hi @tctc91
Ive just tested with version 2.0.0-beta.1, installing react-table and followed the quick start guide here. This is rendering with the responsive table fine for me.
Screenshot 2021-08-17 at 23 08 06

Could you share a minimal repo to check your react-table implementation, as {column.render('Header')} didn't produce what you described above.

@8lane
Copy link
Author

8lane commented Aug 18, 2021

Thanks for the quick reply @KaiSpencer. Apologies, I missed an important point in that my column headers are setup using i18n translations e.g

  const columns: Array<Column> = useMemo(
    () => [
      {
        Header: () => t('locale.path.here'),
        accessor: 'columnId',
      },
    ],
    [],
  )

I'll get a demo setup today

@Tomdango
Copy link
Collaborator

Tomdango commented Sep 7, 2021

Hi, this is a known limitation of the current responsive table implementation - do you think it would be useful to allow React components in cell headers?

@mikemonteith
Copy link

We have a use case for this too:

image

<Table.Row role="row">
  <Table.Cell role="columnheader">Name</Table.Cell>
  <Table.Cell role="columnheader">Email address</Table.Cell>
  <Table.Cell role="columnheader">Permission level</Table.Cell>
  <Table.Cell role="columnheader">Status</Table.Cell>
  <Table.Cell role="columnheader"><span className="nhsuk-u-visually-hidden">Edit user</span></Table.Cell>
</Table.Row>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants