-
Notifications
You must be signed in to change notification settings - Fork 13
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
base: dev
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 9138b7c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
@@ -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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
export const StyledCaption = styled.caption` | ||
display: flex; | ||
flex: 1; | ||
`; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this 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
packages/react-magma-dom/src/components/Datagrid/Datagrid.test.js
Outdated
Show resolved
Hide resolved
tableTitle
prop
…se default to set amount
@@ -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}> |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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"> |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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>}> |
There was a problem hiding this comment.
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.
<Table tableTitle={<Heading level={1} {...args}>Heading component example</Heading>}> | |
<Table {...args} tableTitle={<Heading level={1}>Heading component example</Heading>}> |
@@ -122,6 +128,12 @@ export const TableContainer = styled.div<{ | |||
: props.theme.colors.focus}; | |||
} | |||
`; | |||
export const StyledCaption = styled.caption<{ isInverse: boolean; tableTitleNode: boolean; }>` |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left-aligned please
There was a problem hiding this 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}> |
There was a problem hiding this comment.
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}> |
There was a problem hiding this comment.
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' }; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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)
There was a problem hiding this 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)
Issue: # 1395
What I did
tableTitle
prop for bothTable
andDatagrid
to enable the use of captions and further improve accessibility across both components.Screenshots:
Checklist
How to test