Skip to content

Commit

Permalink
Update MessageBarTitle to support different HTML tags
Browse files Browse the repository at this point in the history
  • Loading branch information
vs4vijay committed Dec 6, 2024
1 parent f42240c commit 0ab8d63
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,13 @@ export const MessageBarTitle: ForwardRefComponent<MessageBarTitleProps>;
export const messageBarTitleClassNames: SlotClassNames<MessageBarTitleSlots>;

// @public
export type MessageBarTitleProps = ComponentProps<MessageBarTitleSlots>;
export type MessageBarTitleProps = ComponentProps<MessageBarTitleSlots> & {
as?: 'span' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'p';
};

// @public (undocumented)
export type MessageBarTitleSlots = {
root: Slot<'span'>;
root: Slot<'span' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'p'>;
};

// @public
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,31 @@ describe('MessageBarTitle', () => {
displayName: 'MessageBarTitle',
});

// TODO add more tests here, and create visual regression tests in /apps/vr-tests

it('renders a default state', () => {
const result = render(<MessageBarTitle>Default MessageBarTitle</MessageBarTitle>);
expect(result.container).toMatchSnapshot();
});

it('renders correctly with different as values', () => {
const { container: containerH1 } = render(<MessageBarTitle as="h1">MessageBarTitle as h1</MessageBarTitle>);
expect(containerH1).toMatchSnapshot();

const { container: containerH2 } = render(<MessageBarTitle as="h2">MessageBarTitle as h2</MessageBarTitle>);
expect(containerH2).toMatchSnapshot();

const { container: containerH3 } = render(<MessageBarTitle as="h3">MessageBarTitle as h3</MessageBarTitle>);
expect(containerH3).toMatchSnapshot();

const { container: containerH4 } = render(<MessageBarTitle as="h4">MessageBarTitle as h4</MessageBarTitle>);
expect(containerH4).toMatchSnapshot();

const { container: containerH5 } = render(<MessageBarTitle as="h5">MessageBarTitle as h5</MessageBarTitle>);
expect(containerH5).toMatchSnapshot();

const { container: containerH6 } = render(<MessageBarTitle as="h6">MessageBarTitle as h6</MessageBarTitle>);
expect(containerH6).toMatchSnapshot();

const { container: containerP } = render(<MessageBarTitle as="p">MessageBarTitle as p</MessageBarTitle>);
expect(containerP).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';

export type MessageBarTitleSlots = {
root: Slot<'span'>;
root: Slot<'span' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'p'>;
};

/**
* MessageBarTitle Props
*/
export type MessageBarTitleProps = ComponentProps<MessageBarTitleSlots>;
export type MessageBarTitleProps = ComponentProps<MessageBarTitleSlots> & {
as?: 'span' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'p';
};

/**
* State used in rendering MessageBarTitle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ export const useMessageBarTitle_unstable = (

return {
components: {
root: 'span',
root: props.as || 'span',
},
root: slot.always(
getIntrinsicElementProps('span', {
getIntrinsicElementProps(props.as || 'span', {
ref,
id: titleId,
...props,
}),
{ elementType: 'span' },
{ elementType: props.as || 'span' },
),
};
};

0 comments on commit 0ab8d63

Please sign in to comment.