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: Forwarding Ref in TableExpandRow component #14950

Merged
merged 6 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1945,6 +1945,7 @@ Map {
},
},
"TableExpandRow": Object {
"$$typeof": Symbol(react.forward_ref),
"propTypes": Object {
"aria-controls": Object {
"type": "string",
Expand Down Expand Up @@ -1979,6 +1980,7 @@ Map {
"type": "func",
},
},
"render": [Function],
},
"TableExpandedRow": Object {
"propTypes": Object {
Expand Down Expand Up @@ -7557,6 +7559,7 @@ Map {
},
},
"TableExpandRow" => Object {
"$$typeof": Symbol(react.forward_ref),
"propTypes": Object {
"aria-controls": Object {
"type": "string",
Expand Down Expand Up @@ -7591,6 +7594,7 @@ Map {
"type": "func",
},
},
"render": [Function],
},
"TableExpandedRow" => Object {
"propTypes": Object {
Expand Down
102 changes: 55 additions & 47 deletions packages/react/src/components/DataTable/TableExpandRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,66 +54,73 @@ interface TableExpandRowProps extends PropsWithChildren<TableRowProps> {
onExpand: MouseEventHandler<HTMLButtonElement>;
}

const TableExpandRow = ({
['aria-controls']: ariaControls,
['aria-label']: ariaLabel,
ariaLabel: deprecatedAriaLabel,
className: rowClassName,
children,
isExpanded,
onExpand,
expandIconDescription,
isSelected,
expandHeader = 'expand',
...rest
}: TableExpandRowProps) => {
const prefix = usePrefix();
const className = cx(
const TableExpandRow = React.forwardRef(
(
{
[`${prefix}--parent-row`]: true,
[`${prefix}--expandable-row`]: isExpanded,
[`${prefix}--data-table--selected`]: isSelected,
},
rowClassName
);
const previousValue = isExpanded ? 'collapsed' : undefined;

return (
<tr {...rest} className={className} data-parent-row>
<TableCell
className={`${prefix}--table-expand`}
data-previous-value={previousValue}
headers={expandHeader}>
<button
type="button"
className={`${prefix}--table-expand__button`}
onClick={onExpand}
title={expandIconDescription}
aria-label={deprecatedAriaLabel || ariaLabel}
aria-expanded={isExpanded}
aria-controls={ariaControls}>
<ChevronRight
className={`${prefix}--table-expand__svg`}
aria-label={expandIconDescription}
/>
</button>
</TableCell>
{children}
</tr>
);
};
['aria-controls']: ariaControls,
['aria-label']: ariaLabel,
ariaLabel: deprecatedAriaLabel,
className: rowClassName,
children,
isExpanded,
onExpand,
expandIconDescription,
isSelected,
expandHeader = 'expand',
...rest
}: TableExpandRowProps,
ref: React.Ref<HTMLTableCellElement>
) => {
const prefix = usePrefix();
const className = cx(
{
[`${prefix}--parent-row`]: true,
[`${prefix}--expandable-row`]: isExpanded,
[`${prefix}--data-table--selected`]: isSelected,
},
rowClassName
);
const previousValue = isExpanded ? 'collapsed' : undefined;

return (
<tr {...rest} ref={ref as never} className={className} data-parent-row>
<TableCell
className={`${prefix}--table-expand`}
data-previous-value={previousValue}
headers={expandHeader}>
<button
type="button"
className={`${prefix}--table-expand__button`}
onClick={onExpand}
title={expandIconDescription}
aria-label={deprecatedAriaLabel || ariaLabel}
aria-expanded={isExpanded}
aria-controls={ariaControls}>
<ChevronRight
className={`${prefix}--table-expand__svg`}
aria-label={expandIconDescription}
/>
</button>
</TableCell>
{children}
</tr>
);
}
);

TableExpandRow.propTypes = {
/**
* Space separated list of one or more ID values referencing the TableExpandedRow(s) being controlled by the TableExpandRow
* TODO: make this required in v12
*/
/**@ts-ignore*/
Copy link
Contributor Author

Choose a reason for hiding this comment

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

carbon

"@types/react": "~17.0.2" breaking prop-types

['aria-controls']: PropTypes.string,

/**
* Specify the string read by a voice reader when the expand trigger is
* focused
*/
/**@ts-ignore*/
['aria-label']: PropTypes.string,

/**
Expand Down Expand Up @@ -152,4 +159,5 @@ TableExpandRow.propTypes = {
onExpand: PropTypes.func.isRequired,
};

TableExpandRow.displayName = 'TableExpandRow';
export default TableExpandRow;
Loading