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

feat(Table, Datagrid): Added new tableTitle prop #1541

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from

Conversation

chris-cedrone-cengage
Copy link
Collaborator

@chris-cedrone-cengage chris-cedrone-cengage commented Nov 8, 2024

Issue: # 1395

What I did

  • New tableTitle prop for both Table and Datagrid to enable the use of captions and further improve accessibility across both components.

Screenshots:

Checklist

  • changeset has been added
  • Pull request description is descriptive
  • I have made corresponding changes to the documentation
  • New and existing unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works

How to test

Copy link

changeset-bot bot commented Nov 8, 2024

🦋 Changeset detected

Latest commit: 9138b7c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
react-magma-dom Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chris-cedrone-cengage chris-cedrone-cengage changed the title Initial commit, working on docs and tests next feat / Table & Data grid captions Nov 8, 2024
Copy link
Contributor

github-actions bot commented Nov 8, 2024

Copy link
Contributor

github-actions bot commented Nov 8, 2024

Copy link
Contributor

github-actions bot commented Nov 8, 2024

Copy link
Contributor

github-actions bot commented Nov 8, 2024

Copy link
Contributor

github-actions bot commented Nov 8, 2024

Copy link
Contributor

github-actions bot commented Nov 8, 2024

Copy link
Contributor

github-actions bot commented Nov 8, 2024

Copy link
Contributor

github-actions bot commented Nov 8, 2024

@@ -51,6 +53,7 @@ export interface DatagridRow {
* Used to allow each unique column field as a key with the row content as the value
*/
[key: string]: any;
tableTitle?: any;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want users to pass a node (React.ReactNode), and maybe also a string? but I don't think we should make this as broad as any

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need to add a description to explain to adopters when to use this

Comment on lines 144 to 147
export const StyledCaption = styled.caption`
display: flex;
flex: 1;
`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check with @orion-cengage what the default heading title styles should be

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you're already exporting it, we should define the StyledCaption in only one place and use it in both Table and Datagrid so they will always be consistent.

Copy link
Contributor

Copy link
Contributor

@chris-cedrone-cengage chris-cedrone-cengage marked this pull request as ready for review November 11, 2024 20:49
@chris-cedrone-cengage chris-cedrone-cengage requested a review from a team as a code owner November 11, 2024 20:49
Copy link
Collaborator

@silvalaura silvalaura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few more changes

website/react-magma-docs/src/pages/api/table.mdx Outdated Show resolved Hide resolved
website/react-magma-docs/src/pages/api/table.mdx Outdated Show resolved Hide resolved
website/react-magma-docs/src/pages/api/datagrid.mdx Outdated Show resolved Hide resolved
packages/react-magma-dom/src/components/Table/Table.tsx Outdated Show resolved Hide resolved
@silvalaura silvalaura changed the title feat / Table & Data grid captions feat(Table, Datagrid): Added new tableTitle prop Nov 11, 2024
Copy link
Contributor

Copy link
Contributor

Copy link
Contributor

Copy link
Contributor

@@ -278,6 +288,12 @@ export const Datagrid = React.forwardRef<HTMLTableElement, DatagridProps>(

return (
<>
{tableTitle && (
<StyledCaption isInverse={props.isInverse} tableTitleNode={typeof tableTitle !== 'string' ? true : false} theme={theme}>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when a prop is a boolean, it's helpful to name it isXXX or hasXXX, so we could rename this to isTitleNode or something similar

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A cleaner way to write typeof tableTitle !== 'string' ? true : false is to directly use the comparison typeof tableTitle !== 'string'. This expression already evaluates to a boolean value, so there is no need to use a ternary operator to return true or false.

@@ -51,7 +52,7 @@ const rows = [

const Template: Story<TableProps> = args => (
<Card isInverse={args.isInverse}>
<Table {...args}>
<Table tableTitle="Basic usage">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we not need ...args anymore?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add some examples where tableTitle is a node?

export const TableTitleWithNode = args => {
return (
<Table tableTitle={<Heading level={1} {...args}>Heading component example</Heading>}>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The args should be on the table, not the heading.

Suggested change
<Table tableTitle={<Heading level={1} {...args}>Heading component example</Heading>}>
<Table {...args} tableTitle={<Heading level={1}>Heading component example</Heading>}>

packages/react-magma-dom/src/components/Table/Table.tsx Outdated Show resolved Hide resolved
@@ -122,6 +128,12 @@ export const TableContainer = styled.div<{
: props.theme.colors.focus};
}
`;
export const StyledCaption = styled.caption<{ isInverse: boolean; tableTitleNode: boolean; }>`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default, captions are centered aligned.

@orion-cengage are you okay with this or should we force a different alignment?
image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left-aligned please

Copy link
Contributor

Copy link
Contributor

Copy link
Collaborator

@silvalaura silvalaura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking back at the original ticket...

I think it's expected for caption to be inside the table tag
<table><caption><h2>This is the title of the table</h2></caption>...

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/caption

export const TableTitleWithNode = args => {
return (
<Table tableTitle={<Heading level={1}>Heading component example</Heading>} {...args}>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because {...args} is at the end, it's replacing tableTitle with the one that gets passed in so it reads Row colors instead of Heading component example

@@ -51,7 +52,7 @@ const rows = [

const Template: Story<TableProps> = args => (
<Card isInverse={args.isInverse}>
<Table {...args}>
<Table tableTitle="Basic usage" {...args}>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't needed as it will always get overwritten by args as long as the Default has tableTitle

@@ -337,18 +343,23 @@ const defaultArgs = {
};

export const Default = Template.bind({});
Default.args = defaultArgs;
Default.args = { ...defaultArgs, tableTitle: 'Default' };
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tableTitle: 'Default' should be moved inside defaultArgs where all the default arguments are

@@ -45,6 +46,11 @@ export interface TableProps extends React.HTMLAttributes<HTMLTableElement> {
*/
minWidth?: number;
rowCount?: number;
/**
* Title that appears above the Datagrid
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should be clear that this will be inserted inside <caption>. Something like

  • The title or caption of a table inside a <caption> HTML element that provides the table an accessible description

(this applies to both Table and DataGrid)

Copy link
Contributor

Copy link
Contributor

Copy link
Contributor

Copy link
Contributor

@silvalaura silvalaura added needs design feedback Waiting for Design approval or feedback do not merge Pull requests that should not be merged labels Nov 12, 2024
Copy link
Collaborator

@silvalaura silvalaura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good. Please do NOT merge until after the release (and @orion-cengage 's approval)

@orion-cengage
Copy link
Contributor

This was definitely not the intended result on this one, and that's probably my fault for not providing a design. I'll take a closer look when I get a bit of time freed up.

image

@silvalaura silvalaura added blocked Blocked by another issue and removed do not merge Pull requests that should not be merged labels Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked Blocked by another issue needs design feedback Waiting for Design approval or feedback
Projects
None yet
Development

Successfully merging this pull request may close these issues.

A11y Fail: Table + Data grid - Need to use Caption as title of table
3 participants