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

fix(ExpandableTile): support forward ref #13390

Merged
merged 7 commits into from
Mar 30, 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 @@ -2954,6 +2954,7 @@ Map {
},
},
"ExpandableTile" => Object {
"$$typeof": Symbol(react.forward_ref),
"defaultProps": Object {
"expanded": false,
"onClick": [Function],
Expand All @@ -2963,7 +2964,6 @@ Map {
"tileMaxHeight": 0,
"tilePadding": 0,
},
"displayName": "ExpandableTile",
"propTypes": Object {
"children": Object {
"type": "node",
Expand Down Expand Up @@ -3000,6 +3000,7 @@ Map {
"type": "string",
},
},
"render": [Function],
},
"FileUploader" => Object {
"contextType": Object {
Expand Down
43 changes: 24 additions & 19 deletions packages/react/src/components/Tile/Tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { composeEventHandlers } from '../../tools/events';
import { usePrefix } from '../../internal/usePrefix';
import useIsomorphicEffect from '../../internal/useIsomorphicEffect';
import { getInteractiveContent } from '../../internal/useNoInteractiveChildren';
import { useMergedRefs } from '../../internal/useMergedRefs';

export const Tile = React.forwardRef(function Tile(
{ children, className, light = false, ...rest },
Expand Down Expand Up @@ -334,22 +335,25 @@ SelectableTile.propTypes = {
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
};

export function ExpandableTile({
tabIndex,
className,
children,
expanded,
tileMaxHeight, // eslint-disable-line
tilePadding, // eslint-disable-line
onClick,
onKeyUp,
tileCollapsedIconText,
tileExpandedIconText,
tileCollapsedLabel,
tileExpandedLabel,
light,
...rest
}) {
export const ExpandableTile = React.forwardRef(function ExpandableTile(
{
tabIndex,
className,
children,
expanded,
tileMaxHeight, // eslint-disable-line
tilePadding, // eslint-disable-line
onClick,
onKeyUp,
tileCollapsedIconText,
tileExpandedIconText,
tileCollapsedLabel,
tileExpandedLabel,
light,
...rest
},
forwardRef
) {
const [isTileMaxHeight, setIsTileMaxHeight] = useState(tileMaxHeight);
const [isTilePadding, setIsTilePadding] = useState(tilePadding);
const [prevExpanded, setPrevExpanded] = useState(expanded);
Expand All @@ -362,6 +366,7 @@ export function ExpandableTile({
const tileContent = useRef(null);
const tile = useRef(null);
const prefix = usePrefix();
const ref = useMergedRefs([forwardRef, tile]);

if (expanded !== prevExpanded) {
setIsExpanded(expanded);
Expand Down Expand Up @@ -476,7 +481,7 @@ export function ExpandableTile({
}, []);
return interactive ? (
<div
ref={tile}
ref={ref}
className={interactiveClassNames}
aria-expanded={isExpanded}
{...rest}>
Expand All @@ -501,7 +506,7 @@ export function ExpandableTile({
) : (
<button
type="button"
ref={tile}
ref={ref}
className={classNames}
aria-expanded={isExpanded}
title={isExpanded ? tileExpandedIconText : tileCollapsedIconText}
Expand All @@ -523,7 +528,7 @@ export function ExpandableTile({
</div>
</button>
);
}
});

ExpandableTile.propTypes = {
/**
Expand Down