Skip to content

Commit a960656

Browse files
fix: Text component to properly pass down ref (#20874)
* fix: Text component to properly pass down ref * add changelog Co-authored-by: Oleksandr Fediashov <[email protected]>
1 parent ac22ac2 commit a960656

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

packages/fluentui/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
6868
- Fix `MenuItemIcon` to allow icon `size` to be in effect @yuanboxue-amber ([#20803](https://github.com/microsoft/fluentui/pull/20803))
6969
- Fix `Pill` components to properly pass ref to root slots @chpalac ([#20838](https://github.com/microsoft/fluentui/pull/20838))
7070
- Fix `MenuButton` component to properly pass ref to root slots @chpalac ([#20837](https://github.com/microsoft/fluentui/pull/20837))
71+
- Fix `Text` component to properly pass ref to root slots @chpalac ([#20874](https://github.com/microsoft/fluentui/pull/20874))
7172
- Fix `TextArea` component to properly pass ref to root slots @chpalac ([#20875](https://github.com/microsoft/fluentui/pull/20875))
7273
- Fix `Tree` component to properly pass ref to root slots @chpalac ([#20877](https://github.com/microsoft/fluentui/pull/20877))
7374
- Fix `Video` component to properly pass ref to root slots @chpalac ([#20878](https://github.com/microsoft/fluentui/pull/20878))

packages/fluentui/react-northstar/src/components/Text/Text.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ import { Accessibility } from '@fluentui/accessibility';
1818

1919
import { FluentComponentStaticProps } from '../../types';
2020
import {
21-
ComponentWithAs,
2221
getElementType,
2322
useUnhandledProps,
2423
useFluentContext,
2524
useAccessibility,
2625
useStyles,
2726
useTelemetry,
27+
ForwardRefWithAs,
2828
} from '@fluentui/react-bindings';
2929

3030
export interface TextProps
@@ -92,7 +92,7 @@ export const textClassName = 'ui-text';
9292
/**
9393
* A Text consistently styles and formats occurrences of text.
9494
*/
95-
export const Text: ComponentWithAs<'span', TextProps> & FluentComponentStaticProps<TextProps> = props => {
95+
export const Text = (React.forwardRef<HTMLSpanElement, TextProps>((props, ref) => {
9696
const context = useFluentContext();
9797
const { setStart, setEnd } = useTelemetry(Text.displayName, context.telemetry);
9898
setStart();
@@ -155,6 +155,7 @@ export const Text: ComponentWithAs<'span', TextProps> & FluentComponentStaticPro
155155
<ElementType
156156
{...getA11Props('root', {
157157
className: classes.root,
158+
ref,
158159
...rtlTextContainer.getAttributes({ forElements: [children, content] }),
159160
...unhandledProps,
160161
})}
@@ -166,12 +167,12 @@ export const Text: ComponentWithAs<'span', TextProps> & FluentComponentStaticPro
166167
setEnd();
167168

168169
return element;
169-
};
170+
}) as unknown) as ForwardRefWithAs<'span', HTMLSpanElement, TextProps> & FluentComponentStaticProps<TextProps>;
170171

171172
Text.displayName = 'Text';
172173

173174
Text.defaultProps = {
174-
as: 'span',
175+
as: 'span' as const,
175176
};
176177
Text.propTypes = {
177178
...commonPropTypes.createCommon({ color: true }),
@@ -180,7 +181,13 @@ Text.propTypes = {
180181
error: PropTypes.bool,
181182
important: PropTypes.bool,
182183
size: customPropTypes.size,
183-
weight: PropTypes.oneOf(['light', 'semilight', 'regular', 'semibold', 'bold']),
184+
weight: PropTypes.oneOf<'light' | 'semilight' | 'regular' | 'semibold' | 'bold'>([
185+
'light',
186+
'semilight',
187+
'regular',
188+
'semibold',
189+
'bold',
190+
]),
184191
success: PropTypes.bool,
185192
temporary: PropTypes.bool,
186193
align: customPropTypes.align,

0 commit comments

Comments
 (0)