Skip to content

Commit fd9ce14

Browse files
authored
fix(expandable section): update to use <Button> for toggle (#10891)
* fix(expandable section): update to use <Button> for toggle * update version and structure * fix cypress tests
1 parent fce7209 commit fd9ce14

File tree

11 files changed

+451
-333
lines changed

11 files changed

+451
-333
lines changed

packages/react-core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"tslib": "^2.6.2"
5555
},
5656
"devDependencies": {
57-
"@patternfly/patternfly": "6.0.0-alpha.210",
57+
"@patternfly/patternfly": "6.0.0-alpha.226",
5858
"case-anything": "^2.1.13",
5959
"css": "^3.0.0",
6060
"fs-extra": "^11.2.0"

packages/react-core/src/components/ExpandableSection/ExpandableSection.tsx

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import AngleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-right-i
66
import { PickOptional } from '../../helpers/typeUtils';
77
import { debounce, getUniqueId } from '../../helpers/util';
88
import { getResizeObserver } from '../../helpers/resizeObserver';
9+
import { Button } from '../Button';
910

1011
export enum ExpandableSectionVariant {
1112
default = 'default',
@@ -228,21 +229,25 @@ class ExpandableSection extends React.Component<ExpandableSectionProps, Expandab
228229
);
229230

230231
const expandableToggle = !isDetached && (
231-
<button
232-
className={css(styles.expandableSectionToggle)}
233-
type="button"
234-
aria-expanded={propOrStateIsExpanded}
235-
aria-controls={uniqueContentId}
236-
id={uniqueToggleId}
237-
onClick={(event) => onToggle(event, !propOrStateIsExpanded)}
238-
>
239-
{variant !== ExpandableSectionVariant.truncate && (
240-
<span className={css(styles.expandableSectionToggleIcon)}>
241-
<AngleRightIcon aria-hidden />
242-
</span>
243-
)}
244-
<span className={css(styles.expandableSectionToggleText)}>{toggleContent || computedToggleText}</span>
245-
</button>
232+
<div className={`${styles.expandableSection}__toggle`}>
233+
<Button
234+
variant="link"
235+
{...(variant === ExpandableSectionVariant.truncate && { isInline: true })}
236+
aria-expanded={propOrStateIsExpanded}
237+
aria-controls={uniqueContentId}
238+
id={uniqueToggleId}
239+
onClick={(event) => onToggle(event, !propOrStateIsExpanded)}
240+
{...(variant !== ExpandableSectionVariant.truncate && {
241+
icon: (
242+
<span className={css(styles.expandableSectionToggleIcon)}>
243+
<AngleRightIcon aria-hidden />
244+
</span>
245+
)
246+
})}
247+
>
248+
{toggleContent || computedToggleText}
249+
</Button>
250+
</div>
246251
);
247252

248253
return (

packages/react-core/src/components/ExpandableSection/ExpandableSectionToggle.tsx

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as React from 'react';
22
import styles from '@patternfly/react-styles/css/components/ExpandableSection/expandable-section';
33
import { css } from '@patternfly/react-styles';
44
import AngleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-right-icon';
5+
import { Button } from '../Button';
56

67
/** Acts as the toggle sub-component when the main expandable section component has the isDetached
78
* property passed in. Allows for more custom control over the expandable section's toggle.
@@ -50,26 +51,30 @@ export const ExpandableSectionToggle: React.FunctionComponent<ExpandableSectionT
5051
)}
5152
{...props}
5253
>
53-
<button
54-
className={css(styles.expandableSectionToggle)}
55-
type="button"
56-
aria-expanded={isExpanded}
57-
aria-controls={contentId}
58-
onClick={() => onToggle(!isExpanded)}
59-
id={toggleId}
60-
>
61-
{!hasTruncatedContent && (
62-
<span
63-
className={css(
64-
styles.expandableSectionToggleIcon,
65-
isExpanded && direction === 'up' && styles.modifiers.expandTop
66-
)}
67-
>
68-
<AngleRightIcon aria-hidden />
69-
</span>
70-
)}
71-
<span className={css(styles.expandableSectionToggleText)}>{children}</span>
72-
</button>
54+
<div className={`${styles.expandableSection}__toggle`}>
55+
<Button
56+
variant="link"
57+
{...(hasTruncatedContent && { isInline: true })}
58+
aria-expanded={isExpanded}
59+
aria-controls={contentId}
60+
onClick={() => onToggle(!isExpanded)}
61+
id={toggleId}
62+
{...(!hasTruncatedContent && {
63+
icon: (
64+
<span
65+
className={css(
66+
styles.expandableSectionToggleIcon,
67+
isExpanded && direction === 'up' && styles.modifiers.expandTop
68+
)}
69+
>
70+
<AngleRightIcon aria-hidden />
71+
</span>
72+
)
73+
})}
74+
>
75+
{children}
76+
</Button>
77+
</div>
7378
</div>
7479
);
7580

0 commit comments

Comments
 (0)