Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion packages/react/src/ActionList/TrailingAction.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import type React from 'react'
import {forwardRef} from 'react'
import {forwardRef, useContext} from 'react'
import {Button, IconButton} from '../Button'
import type {IconButtonProps} from '../Button/types'
import type {ForwardRefComponent as PolymorphicForwardRefComponent} from '../utils/polymorphic'
import {clsx} from 'clsx'
import classes from './ActionList.module.css'
import {ActionListContainerContext} from './ActionListContainerContext'

type ElementProps =
| {
Expand Down Expand Up @@ -34,6 +35,17 @@
{as = 'button', icon, label, href = null, className, style, loading, tooltipDirection = 'w', ...props},
forwardedRef,
) => {
// Use context from ActionList
const {selectionVariant} = useContext(ActionListContainerContext)
// TODO: Rename
const withinMenu = selectionVariant === 'single' || selectionVariant === 'multiple'

if (withinMenu) {
console.log(

Check failure on line 44 in packages/react/src/ActionList/TrailingAction.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
'Warning: ActionList.TrailingAction should not be used within selectable ActionLists. Please remove it to avoid unexpected behavior.',
)
}

return (
<span
className={clsx(className, classes.TrailingAction)}
Expand All @@ -53,6 +65,8 @@
// @ts-expect-error StyledButton wants both Anchor and Button refs
ref={forwardedRef}
className={classes.TrailingActionButton}
aria-hidden={!withinMenu ? 'true' : undefined}
tabIndex={!withinMenu ? -1 : undefined}
{...props}
/>
) : (
Expand All @@ -66,6 +80,7 @@
data-has-label="true"
ref={forwardedRef}
className={classes.TrailingActionButton}
aria-hidden={withinMenu ? 'true' : undefined}
{...props}
>
{label}
Expand Down
25 changes: 25 additions & 0 deletions packages/react/src/AnchoredOverlay/AnchoredOverlay.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,31 @@ describe('AnchoredOverlay feature flag specific behavior', () => {
expect(anchor!.getAttribute('popovertarget')).toBe(overlay!.getAttribute('id'))
})

it('preserves a consumer ID for the popover and its invoker target', async () => {
render(
<FeatureFlags flags={{primer_react_css_anchor_positioning: true}}>
<BaseStyles>
<AnchoredOverlay
open
renderAs="popover"
overlayProps={{id: 'consumer.popover', role: 'dialog', 'aria-label': 'Custom popover'}}
renderAnchor={props => <Button {...props}>Custom anchor</Button>}
>
<button type="button">Focusable child</button>
</AnchoredOverlay>
</BaseStyles>
</FeatureFlags>,
)
const dialog = page.getByRole('dialog', {name: 'Custom popover', exact: true})
await expect.element(dialog).toBeVisible()
expect(dialog.element()).toHaveAttribute('id', 'consumer.popover')
expect(page.getByRole('button', {name: 'Custom anchor', exact: true}).element()).toHaveAttribute(
'popovertarget',
'consumer.popover',
)
expect(dialog.element().matches(':popover-open')).toBe(true)
})

it('should not set popover attribute on overlay when renderAs is "portal"', () => {
const {baseElement} = render(
<FeatureFlags flags={{primer_react_css_anchor_positioning: true}}>
Expand Down
11 changes: 7 additions & 4 deletions packages/react/src/AnchoredOverlay/AnchoredOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,11 @@ export const AnchoredOverlay: React.FC<React.PropsWithChildren<AnchoredOverlayPr
})

const popoverId = useId()
const overlayId = overlayProps?.id ?? popoverId
const popoverTargetProps = shouldRenderAsPopover
? reactMajorVersion >= 19
? {popoverTarget: popoverId}
: {popovertarget: popoverId}
? {popoverTarget: overlayId}
: {popovertarget: overlayId}
: {}
const id = popoverId.replaceAll(':', '_') // popoverId can contain colons which are invalid in CSS custom property names, so we replace them with underscores
const anchorName = `--anchored-overlay-anchor-${id}`
Expand Down Expand Up @@ -396,7 +397,9 @@ export const AnchoredOverlay: React.FC<React.PropsWithChildren<AnchoredOverlayPr
cssAnchorPositioningSettings?.fallbackStrategy,
])

const showXIcon = onClose && variant.narrow === 'fullscreen' && displayCloseButton
const showXIcon =
(onClose && variant.narrow === 'fullscreen' && displayCloseButton) || (onClose && displayCloseButton)

const XButtonAriaLabelledBy = closeButtonProps['aria-labelledby']
const XButtonAriaLabel = closeButtonProps['aria-label']

Expand Down Expand Up @@ -436,7 +439,7 @@ export const AnchoredOverlay: React.FC<React.PropsWithChildren<AnchoredOverlayPr
_PrivateDisablePortal={_PrivateDisablePortal}
{...(shouldRenderAsPopover ? {popover: 'manual'} : {})}
{...restOverlayProps}
{...(shouldRenderAsPopover ? {id: popoverId} : {})}
{...(shouldRenderAsPopover ? {id: overlayId} : {})}
ref={node => mergedOverlayRef(node)}
data-anchor-position={cssAnchorPositioning}
data-side={cssAnchorPositioning ? side : position?.anchorSide}
Expand Down
3 changes: 3 additions & 0 deletions packages/react/src/FeatureFlags/DefaultFeatureFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import {FeatureFlagScope} from './FeatureFlagScope'

export const DefaultFeatureFlags = FeatureFlagScope.create({
primer_react_css_anchor_positioning: false,
primer_react_select_panel_composable_adapter: false,
primer_react_select_panel_native_dialog: false,
primer_react_select_panel_native_invokers: false,
primer_react_select_panel_fullscreen_on_narrow: false,
primer_react_select_panel_legacy_contrast: false,
primer_react_select_panel_order_selected_at_top: false,
Expand Down
Loading
Loading