Skip to content

Commit

Permalink
fix: embed component to properly pass ref (#20703)
Browse files Browse the repository at this point in the history
* fix: embed component to properly pass ref

* add changelog
  • Loading branch information
chpalac authored Nov 22, 2021
1 parent c4e248b commit 5ade517
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/fluentui/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Fix `Card` comoponent to properly pass ref to root slots @chpalac ([#20644](https://github.com/microsoft/fluentui/pull/20644))
- Fix `Dropdown` by conditionally adding `aria-expanded="true"` to the button trigger @chpalac ([#20671](https://github.com/microsoft/fluentui/pull/20671))
- Optimized `felaInvokeKeyframesPlugin` to not create new objects but reuse existing one in `reduce` @mbman ([#20649](https://github.com/microsoft/fluentui/pull/20649))
- Fix `Embed` component to properly pass ref to root slots @chpalac ([#20703](https://github.com/microsoft/fluentui/pull/20703))
- Fix `Chat` components to properly pass ref to root slots @chpalac ([#20691](https://github.com/microsoft/fluentui/pull/20691))

### Features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import { Box, BoxProps } from '../Box/Box';
import { ComponentEventHandler, ShorthandValue, FluentComponentStaticProps } from '../../types';
import { Ref } from '@fluentui/react-component-ref';
import {
ComponentWithAs,
getElementType,
useUnhandledProps,
useFluentContext,
useAutoControlled,
useAccessibility,
useTelemetry,
useStyles,
ForwardRefWithAs,
} from '@fluentui/react-bindings';

export interface EmbedSlotClassNames {
Expand Down Expand Up @@ -83,7 +83,7 @@ export type EmbedStylesProps = Required<Pick<EmbedProps, 'active'>> & { iframeLo
* A `placeholder` slot represents an [`Image`](/components/image/definition) component, please follow recommendations from its
* accessibility section.
*/
export const Embed: ComponentWithAs<'span', EmbedProps> & FluentComponentStaticProps<EmbedProps> = props => {
export const Embed = (React.forwardRef<HTMLSpanElement, EmbedProps>((props, ref) => {
const context = useFluentContext();
const { setStart, setEnd } = useTelemetry(Embed.displayName, context.telemetry);
setStart();
Expand Down Expand Up @@ -168,6 +168,7 @@ export const Embed: ComponentWithAs<'span', EmbedProps> & FluentComponentStaticP
{...getA11yProps('root', {
className: classes.root,
onClick: handleClick,
ref,
...unhandledProps,
})}
>
Expand Down Expand Up @@ -218,7 +219,7 @@ export const Embed: ComponentWithAs<'span', EmbedProps> & FluentComponentStaticP
setEnd();

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

Embed.displayName = 'Embed';

Expand All @@ -238,7 +239,7 @@ Embed.propTypes = {
};

Embed.defaultProps = {
as: 'span',
as: 'span' as const,
accessibility: embedBehavior,
control: {},
variables: {},
Expand Down

0 comments on commit 5ade517

Please sign in to comment.