Skip to content

Commit

Permalink
fix: Header components to properly pass ref to root slots (#20811)
Browse files Browse the repository at this point in the history
* fix: Header components to properly pass ref to root slots

* add changelog
  • Loading branch information
chpalac authored Nov 30, 2021
1 parent 5ac95a1 commit 9b0210f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
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 `Header` components to properly pass ref to root slots @chpalac ([#20811](https://github.com/microsoft/fluentui/pull/20811))
- Fix `Grid` component to properly pass ref to root slots @chpalac ([#20810](https://github.com/microsoft/fluentui/pull/20810))
- Fix `Form` components to properly pass ref to root slots @chpalac ([#20809](https://github.com/microsoft/fluentui/pull/20809))
- Fix `Loader` component to properly pass ref to root slots @chpalac ([#20814](https://github.com/microsoft/fluentui/pull/20814))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import { HeaderDescription, HeaderDescriptionProps } from './HeaderDescription';

import { ShorthandValue, FluentComponentStaticProps } from '../../types';
import {
ComponentWithAs,
useTelemetry,
useAccessibility,
useFluentContext,
getElementType,
useUnhandledProps,
useStyles,
ForwardRefWithAs,
} from '@fluentui/react-bindings';

export interface HeaderProps
Expand Down Expand Up @@ -57,10 +57,7 @@ export type HeaderStylesProps = Required<Pick<HeaderProps, 'align' | 'color'>> &
* Other considerations:
* - when the description property is used in header, readers will narrate both header content and description within the element. In addition to that, both will be displayed in the list of headings.
*/
export const Header: ComponentWithAs<'h1', HeaderProps> &
FluentComponentStaticProps<HeaderProps> & {
Description: typeof HeaderDescription;
} = props => {
export const Header = (React.forwardRef<HTMLHeadingElement, HeaderProps>((props, ref) => {
const context = useFluentContext();
const { setStart, setEnd } = useTelemetry(Header.displayName, context.telemetry);
setStart();
Expand Down Expand Up @@ -95,6 +92,7 @@ export const Header: ComponentWithAs<'h1', HeaderProps> &
<ElementType
{...getA11yProps('root', {
className: classes.root,
ref,
...unhandledProps,
...rtlTextContainer.getAttributes({
forElements: [children, content],
Expand All @@ -113,7 +111,10 @@ export const Header: ComponentWithAs<'h1', HeaderProps> &
setEnd();

return element;
};
}) as unknown) as ForwardRefWithAs<'h1', HTMLHeadingElement, HeaderProps> &
FluentComponentStaticProps<HeaderProps> & {
Description: typeof HeaderDescription;
};

Header.displayName = 'Header';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import {

import { FluentComponentStaticProps } from '../../types';
import {
ComponentWithAs,
useTelemetry,
useFluentContext,
getElementType,
useUnhandledProps,
useAccessibility,
useStyles,
ForwardRefWithAs,
} from '@fluentui/react-bindings';

export interface HeaderDescriptionProps
Expand All @@ -40,8 +40,7 @@ export type HeaderDescriptionStylesProps = Pick<HeaderDescriptionProps, 'color'>
/**
* A HeaderDescription provides more detailed information about the Header.
*/
export const HeaderDescription: ComponentWithAs<'p', HeaderDescriptionProps> &
FluentComponentStaticProps<HeaderDescriptionProps> = props => {
export const HeaderDescription = (React.forwardRef<HTMLParagraphElement, HeaderDescriptionProps>((props, ref) => {
const context = useFluentContext();
const { setStart, setEnd } = useTelemetry(HeaderDescription.displayName, context.telemetry);
setStart();
Expand Down Expand Up @@ -72,6 +71,7 @@ export const HeaderDescription: ComponentWithAs<'p', HeaderDescriptionProps> &
<ElementType
{...getA11yProps('root', {
className: classes.root,
ref,
...unhandledProps,
...rtlTextContainer.getAttributes({ forElements: [children, content] }),
})}
Expand All @@ -81,7 +81,8 @@ export const HeaderDescription: ComponentWithAs<'p', HeaderDescriptionProps> &
);
setEnd();
return element;
};
}) as unknown) as ForwardRefWithAs<'p', HTMLParagraphElement, HeaderDescriptionProps> &
FluentComponentStaticProps<HeaderDescriptionProps>;

HeaderDescription.displayName = 'HeaderDescription';

Expand Down

0 comments on commit 9b0210f

Please sign in to comment.