diff --git a/.changeset/silent-buses-knock.md b/.changeset/silent-buses-knock.md new file mode 100644 index 00000000000..800a06860b3 --- /dev/null +++ b/.changeset/silent-buses-knock.md @@ -0,0 +1,14 @@ +--- +"@primer/react": minor +--- + +Add data-component attributes and associated tests for: + +SplitPageLayout +Stack +StateLabel +SubNav +TabNav +Text +TextArea +ThemeProvider diff --git a/packages/react/src/PageLayout/PageLayout.tsx b/packages/react/src/PageLayout/PageLayout.tsx index 1fcbbc78f97..17ab7e8ca2f 100644 --- a/packages/react/src/PageLayout/PageLayout.tsx +++ b/packages/react/src/PageLayout/PageLayout.tsx @@ -67,6 +67,7 @@ export type PageLayoutProps = { _slotsConfig?: Record<'header' | 'footer' | 'sidebar', React.ElementType> className?: string style?: React.CSSProperties + 'data-component'?: string } // TODO: refs @@ -79,6 +80,7 @@ const Root: React.FC> = ({ className, style, _slotsConfig: slotsConfig, + 'data-component': dataComponent = 'PageLayout', }) => { const paneRef = useRef(null) const contentWrapperRef = useRef(null) @@ -101,7 +103,13 @@ const Root: React.FC> = ({ return ( - + {slots.sidebar}
{slots.header} @@ -120,7 +128,10 @@ const RootWrapper = memo( children, className, hasSidebar, - }: React.PropsWithChildren & {hasSidebar?: boolean}>) => { + dataComponent, + }: React.PropsWithChildren< + Pick & {hasSidebar?: boolean; dataComponent: string} + >) => { return (
{children} @@ -549,6 +560,7 @@ export type PageLayoutHeaderProps = { hidden?: boolean | ResponsiveValue className?: string style?: React.CSSProperties + 'data-component'?: string } const Header: FCWithSlotMarker> = ({ @@ -561,6 +573,7 @@ const Header: FCWithSlotMarker> = children, style, className, + 'data-component': dataComponent = 'PageLayout.Header', }) => { // Combine divider and dividerWhenNarrow for backwards compatibility const dividerProp = @@ -574,7 +587,7 @@ const Header: FCWithSlotMarker> =
className?: string style?: React.CSSProperties + 'data-component'?: string } // TODO: Account for pane width when centering content @@ -645,6 +659,7 @@ const Content: FCWithSlotMarker> children, className, style, + 'data-component': dataComponent = 'PageLayout.Content', }) => { const Component = as const {contentWrapperRef} = React.useContext(PageLayoutContext) @@ -654,7 +669,7 @@ const Content: FCWithSlotMarker> ref={contentWrapperRef} aria-label={label} aria-labelledby={labelledBy} - data-component="PageLayout.Content" + data-component={dataComponent} style={style} className={clsx(classes.ContentWrapper, className)} {...getResponsiveAttributes('is-hidden', hidden)} @@ -750,6 +765,7 @@ export type PageLayoutPaneBaseProps = { id?: string className?: string style?: React.CSSProperties + 'data-component'?: string } export type PageLayoutPaneProps = PageLayoutPaneBaseProps & @@ -799,6 +815,7 @@ const Pane = React.forwardRef { @@ -902,7 +919,7 @@ const Pane = React.forwardRef { @@ -1237,7 +1256,7 @@ const Sidebar = React.forwardRef className?: string style?: React.CSSProperties + 'data-component'?: string } const Footer: FCWithSlotMarker> = ({ @@ -1325,6 +1345,7 @@ const Footer: FCWithSlotMarker> = children, className, style, + 'data-component': dataComponent = 'PageLayout.Footer', }) => { // Combine divider and dividerWhenNarrow for backwards compatibility const dividerProp = @@ -1338,7 +1359,7 @@ const Footer: FCWithSlotMarker> =