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: Label component to properly pass down ref to root slot #20813

Merged
merged 3 commits into from
Nov 30, 2021
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
1 change: 1 addition & 0 deletions packages/fluentui/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Fix `Chat` components to properly pass ref to root slots @chpalac ([#20691](https://github.com/microsoft/fluentui/pull/20691))
- Fix `Flex` component to properly pass ref to root slots @chpalac ([#20752](https://github.com/microsoft/fluentui/pull/20752))
- Fix `Animation` to expose `Transition` state for the consumer @chpalac ([#20776](https://github.com/microsoft/fluentui/pull/20776))
- Fix `Label` component to properly pass ref to root slots @chpalac ([#20813](https://github.com/microsoft/fluentui/pull/20813))
- Fix `MenuItemIcon` to allow icon `size` to be in effect @yuanboxue-amber ([#20803](https://github.com/microsoft/fluentui/pull/20803))

### Features
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Accessibility } from '@fluentui/accessibility';
import {
ComponentWithAs,
getElementType,
useUnhandledProps,
useAccessibility,
useFluentContext,
useStyles,
useTelemetry,
ForwardRefWithAs,
} from '@fluentui/react-bindings';
import * as customPropTypes from '@fluentui/react-proptypes';
import * as _ from 'lodash';
Expand Down Expand Up @@ -68,7 +68,7 @@ export const labelClassName = 'ui-label';
/**
* A Label allows user to classify content.
*/
export const Label: ComponentWithAs<'span', LabelProps> & FluentComponentStaticProps = props => {
export const Label = (React.forwardRef<HTMLSpanElement, LabelProps>((props, ref) => {
const context = useFluentContext();
const { setStart, setEnd } = useTelemetry(Label.displayName, context.telemetry);
setStart();
Expand Down Expand Up @@ -116,6 +116,7 @@ export const Label: ComponentWithAs<'span', LabelProps> & FluentComponentStaticP
<ElementType
{...getA11Props('root', {
className: classes.root,
ref,
...rtlTextContainer.getAttributes({ forElements: [children] }),
...unhandledProps,
})}
Expand Down Expand Up @@ -166,7 +167,7 @@ export const Label: ComponentWithAs<'span', LabelProps> & FluentComponentStaticP
setEnd();

return element;
};
}) as unknown) as ForwardRefWithAs<'span', HTMLSpanElement, LabelProps> & FluentComponentStaticProps;

Label.displayName = 'Label';

Expand Down