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

[Expandable] Propagate attributes #127

Merged
merged 2 commits into from
Aug 9, 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
16 changes: 12 additions & 4 deletions src/components/Expandable/Expandable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import type { ReactNode } from 'react';
import { useEffect } from 'react';
import { Icon } from '../Icon/Icon';

export interface ExpandableProperties {
export interface ExpandableProperties
extends React.HTMLAttributes<HTMLDivElement> {
header: string;
children: ReactNode;
inAccordion?: boolean;
Expand All @@ -16,7 +17,9 @@ export const Expandable: React.FC<ExpandableProperties> = ({
header,
children,
inAccordion = false,
openOnLoad = false
openOnLoad = false,
className = '',
...properties
}) => {
useEffect(() => {
if (inAccordion) return; // Initialization happens in parent component
Expand All @@ -29,13 +32,18 @@ export const Expandable: React.FC<ExpandableProperties> = ({
'o-expandable',
'o-expandable__padded',
'o-expandable__background',
'o-expandable__border'
'o-expandable__border',
className
];

if (openOnLoad) expandableClasses.push('o-expandable__onload-open');

return (
<div className={classnames(expandableClasses)} data-testid='expandable'>
<div
className={classnames(expandableClasses)}
data-testid='expandable'
{...properties}
>
<button
type='button'
className='o-expandable_header o-expandable_target'
Expand Down
14 changes: 9 additions & 5 deletions src/components/Expandable/ExpandableGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Expandable as CFPB_Expandable } from '@cfpb/cfpb-expandables/src/Expandable';
import classnames from 'classnames';
import type { ReactElement } from 'react';
import React, { useEffect } from 'react';
import type { ExpandableProperties } from './Expandable';

export interface ExpandableGroupProperties {
export interface ExpandableGroupProperties
extends React.HTMLAttributes<HTMLDivElement> {
groupId: string;
accordion?: boolean;
children?: ReactElement<ExpandableProperties>[];
Expand All @@ -12,10 +14,12 @@ export interface ExpandableGroupProperties {
export const ExpandableGroup: React.FC<ExpandableGroupProperties> = ({
groupId,
accordion = false,
children
children,
className = '',
...properties
}) => {
let cname = 'o-expandable-group';
if (accordion) cname += ' o-expandable-group__accordion';
const cname = ['o-expandable-group', className];
if (accordion) cname.push('o-expandable-group__accordion');

useEffect(() => {
if (!accordion) return;
Expand All @@ -34,7 +38,7 @@ export const ExpandableGroup: React.FC<ExpandableGroupProperties> = ({
return child;
});
return (
<div id={groupId} className={cname}>
<div id={groupId} className={classnames(cname)} {...properties}>
{childrenWithProperties}
</div>
);
Expand Down