Skip to content

Commit 7f4def0

Browse files
authored
fix(list): forward refs to component exports (#886)
1 parent c9b12e3 commit 7f4def0

File tree

1 file changed

+24
-24
lines changed
  • packages/paste-core/components/list/src

1 file changed

+24
-24
lines changed

packages/paste-core/components/list/src/index.tsx

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ interface BaseListProps extends React.OlHTMLAttributes<HTMLElement> {
1010
marginBottom?: Space;
1111
}
1212

13-
const List: React.FC<BaseListProps> = ({as, children, ...props}) => {
13+
const List = React.forwardRef<HTMLOListElement | HTMLUListElement, BaseListProps>(({as, children, ...props}, ref) => {
1414
return (
1515
<Text
1616
{...props}
17+
ref={ref}
1718
as={as}
1819
marginLeft="space70"
1920
fontSize="fontSize30"
@@ -24,58 +25,57 @@ const List: React.FC<BaseListProps> = ({as, children, ...props}) => {
2425
{children}
2526
</Text>
2627
);
27-
};
28-
28+
});
2929
List.displayName = 'List';
3030

3131
/*
3232
* Ordered List
3333
*/
3434
export type OrderedListProps = Omit<BaseListProps, 'as'>;
35-
const OrderedList: React.FC<OrderedListProps> = ({children, marginTop, marginBottom, ...props}) => {
36-
return (
37-
<List {...safelySpreadTextProps(props)} as="ol" marginTop={marginTop} marginBottom={marginBottom}>
38-
{children}
39-
</List>
40-
);
41-
};
4235

36+
const OrderedList = React.forwardRef<HTMLOListElement, OrderedListProps>(
37+
({children, marginTop, marginBottom, ...props}, ref) => {
38+
return (
39+
<List {...safelySpreadTextProps(props)} ref={ref} as="ol" marginTop={marginTop} marginBottom={marginBottom}>
40+
{children}
41+
</List>
42+
);
43+
}
44+
);
4345
OrderedList.defaultProps = {
4446
marginBottom: 'space70',
4547
};
46-
4748
if (process.env.NODE_ENV === 'development') {
4849
OrderedList.propTypes = {
4950
marginTop: isMarginTokenProp,
5051
marginBottom: isMarginTokenProp,
5152
};
5253
}
53-
5454
OrderedList.displayName = 'OrderedList';
5555

5656
/*
5757
* Unordered List
5858
*/
5959
export type UnorderedListProps = Omit<BaseListProps, 'as'>;
60-
const UnorderedList: React.FC<UnorderedListProps> = ({children, marginTop, marginBottom, ...props}) => {
61-
return (
62-
<List {...safelySpreadTextProps(props)} as="ul" marginTop={marginTop} marginBottom={marginBottom}>
63-
{children}
64-
</List>
65-
);
66-
};
6760

61+
const UnorderedList = React.forwardRef<HTMLUListElement, UnorderedListProps>(
62+
({children, marginTop, marginBottom, ...props}, ref) => {
63+
return (
64+
<List {...safelySpreadTextProps(props)} ref={ref} as="ul" marginTop={marginTop} marginBottom={marginBottom}>
65+
{children}
66+
</List>
67+
);
68+
}
69+
);
6870
UnorderedList.defaultProps = {
6971
marginBottom: 'space70',
7072
};
71-
7273
if (process.env.NODE_ENV === 'development') {
7374
UnorderedList.propTypes = {
7475
marginTop: isMarginTokenProp,
7576
marginBottom: isMarginTokenProp,
7677
};
7778
}
78-
7979
UnorderedList.displayName = 'UnorderedList';
8080

8181
/*
@@ -86,10 +86,11 @@ export interface ListItemProps extends React.LiHTMLAttributes<HTMLLIElement> {
8686
style?: never;
8787
}
8888

89-
const ListItem: React.FC<ListItemProps> = props => {
89+
const ListItem = React.forwardRef<HTMLLIElement, ListItemProps>((props, ref) => {
9090
return (
9191
<Text
9292
{...safelySpreadTextProps(props)}
93+
ref={ref}
9394
as="li"
9495
marginTop="space30"
9596
marginBottom="space30"
@@ -101,8 +102,7 @@ const ListItem: React.FC<ListItemProps> = props => {
101102
{props.children}
102103
</Text>
103104
);
104-
};
105-
105+
});
106106
ListItem.displayName = 'ListItem';
107107

108108
export {OrderedList, UnorderedList, ListItem};

0 commit comments

Comments
 (0)