Skip to content

Commit 6012a4f

Browse files
authored
[Ref-Conformance] Adding a forwardRef to react-internal Check (#15622)
* Adding a forwardRef to Check.base and removing disabledTests. * Change files * PR feedback
1 parent 3545f57 commit 6012a4f

5 files changed

+24
-16
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"type": "patch",
3+
"comment": "Adding a forwardRef to Check (ref-conformance)",
4+
"packageName": "@fluentui/react-internal",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch",
7+
"date": "2020-10-20T20:37:56.768Z"
8+
}

packages/react-internal/etc/react-internal.api.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1491,7 +1491,7 @@ export interface ICalloutProps extends React.HTMLAttributes<HTMLDivElement>, Rea
14911491
}
14921492

14931493
// @public (undocumented)
1494-
export interface ICheckProps {
1494+
export interface ICheckProps extends React.RefAttributes<HTMLDivElement> {
14951495
// @deprecated (undocumented)
14961496
alwaysShowCheck?: boolean;
14971497
checked?: boolean;

packages/react-internal/src/components/Check/Check.base.tsx

+13-11
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@ import { ICheckStyleProps, ICheckStyles } from './Check.types';
66

77
const getClassNames = classNamesFunction<ICheckStyleProps, ICheckStyles>();
88

9-
export const CheckBase: React.FunctionComponent<ICheckProps> = props => {
10-
const { checked = false, className, theme, styles, useFastIcons = true } = props;
9+
export const CheckBase: React.FunctionComponent<ICheckProps> = React.forwardRef<HTMLDivElement, ICheckProps>(
10+
(props, ref) => {
11+
const { checked = false, className, theme, styles, useFastIcons = true } = props;
1112

12-
const classNames = getClassNames(styles!, { theme: theme!, className, checked });
13-
const IconComponent = useFastIcons ? FontIcon : Icon;
13+
const classNames = getClassNames(styles!, { theme: theme!, className, checked });
14+
const IconComponent = useFastIcons ? FontIcon : Icon;
1415

15-
return (
16-
<div className={classNames.root}>
17-
<IconComponent iconName="CircleRing" className={classNames.circle} />
18-
<IconComponent iconName="StatusCircleCheckmark" className={classNames.check} />
19-
</div>
20-
);
21-
};
16+
return (
17+
<div className={classNames.root} ref={ref}>
18+
<IconComponent iconName="CircleRing" className={classNames.circle} />
19+
<IconComponent iconName="StatusCircleCheckmark" className={classNames.check} />
20+
</div>
21+
);
22+
},
23+
);
2224
CheckBase.displayName = 'CheckBase';

packages/react-internal/src/components/Check/Check.test.tsx

-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,5 @@ describe('Check', () => {
55
isConformant({
66
Component: Check,
77
displayName: 'Check',
8-
// Problem: Is FunctionComponent but missing `forwardRef`
9-
// Solution: add forwardRef and ref typing
10-
disabledTests: ['component-has-root-ref', 'component-handles-ref'],
118
});
129
});

packages/react-internal/src/components/Check/Check.types.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import * as React from 'react';
12
import { IStyle, ITheme } from '../../Styling';
23
import { IRefObject, IStyleFunctionOrObject } from '../../Utilities';
34

45
/**
56
* {@docCategory Check}
67
*/
7-
export interface ICheckProps {
8+
export interface ICheckProps extends React.RefAttributes<HTMLDivElement> {
89
/**
910
* Gets the component ref.
1011
*/

0 commit comments

Comments
 (0)