Skip to content
Merged
5 changes: 5 additions & 0 deletions .changeset/rotten-hats-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': patch
---

Updated PageLayout.Pane to conditionally include id prop
1 change: 1 addition & 0 deletions src/PageLayout/PageLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@ const Pane = React.forwardRef<HTMLDivElement, React.PropsWithChildren<PageLayout
'--pane-max-width-diff': '959px',
},
})}
{...(id && {id: paneId})}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you feel about simplifying to this?

Suggested change
{...(id && {id: paneId})}
id={id}

If id is undefined, it won't pass id to the underlying component.

If id is defined, paneId and id will be the same, so we can use either.

>
{resizable && (
<VisuallyHidden>
Expand Down
6 changes: 6 additions & 0 deletions src/SplitPageLayout/SplitPageLayout.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ const meta: Meta = {
control: {type: 'radio'},
table: {category: 'Pane props'},
},
'Pane.id': {
type: 'string',
defaultValue: 'customId',
table: {category: 'Pane props'},
},
'Pane.position.narrow': {
type: {
name: 'enum',
Expand Down Expand Up @@ -351,6 +356,7 @@ const Template: Story = args => (
regular: args['Pane.hidden.regular'],
wide: args['Pane.hidden.wide'],
}}
id={args['Pane.id']}
>
<Placeholder height={args['Pane placeholder height']} label="Pane" />
</SplitPageLayout.Pane>
Expand Down
15 changes: 15 additions & 0 deletions src/SplitPageLayout/SplitPageLayout.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ describe('SplitPageLayout', () => {
</SplitPageLayout>
</ThemeProvider>,
)

expect(container).toMatchSnapshot()
})

it('renders Pane with a custom ID', () => {
const {getByText} = render(
<ThemeProvider>
<SplitPageLayout>
<SplitPageLayout.Pane id="customId">Pane Content</SplitPageLayout.Pane>
</SplitPageLayout>
</ThemeProvider>,
)

const pane = getByText('Pane Content')

expect(pane.getAttribute('id')).toBe('customId')
})
})