Skip to content

fix(s2): apply styling to CardView when using an action bar #7795

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 27, 2025
Merged
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
12 changes: 9 additions & 3 deletions packages/@react-spectrum/s2/src/CardView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ const cardViewStyles = style({
outlineOffset: -2
}, getAllowedOverrides({height: true}));

const wrapperStyles = style({
position: 'relative',
overflow: 'clip',
size: 'fit'
}, getAllowedOverrides({height: true}));

export const CardViewContext = createContext<ContextValue<Partial<CardViewProps<any>>, DOMRefValue<HTMLDivElement>>>(null);

export const CardView = /*#__PURE__*/ (forwardRef as forwardRefType)(function CardView<T extends object>(props: CardViewProps<T>, ref: DOMRef<HTMLDivElement>) {
Expand Down Expand Up @@ -242,14 +248,14 @@ export const CardView = /*#__PURE__*/ (forwardRef as forwardRefType)(function Ca
defaultSelectedKeys={undefined}
onSelectionChange={onSelectionChange}
style={{
...UNSAFE_style,
...(!props.renderActionBar ? UNSAFE_style : {}),
// Add padding at the bottom when the action bar is visible so users can scroll to the last items.
// Also add scroll padding so keyboard navigating preserves the padding.
paddingBottom: actionBarHeight > 0 ? actionBarHeight + options.minSpace.height : 0,
scrollPadding: options.minSpace.height,
scrollPaddingBottom: actionBarHeight + options.minSpace.height
}}
className={renderProps => UNSAFE_className + cardViewStyles({...renderProps, isLoading: props.loadingState === 'loading'}, styles)}>
className={renderProps => (!props.renderActionBar ? UNSAFE_className : '') + cardViewStyles({...renderProps, isLoading: props.loadingState === 'loading'}, !props.renderActionBar ? styles : undefined)}>
{children}
</AriaGridList>
</ImageCoordinator>
Expand All @@ -262,7 +268,7 @@ export const CardView = /*#__PURE__*/ (forwardRef as forwardRefType)(function Ca
// ActionBar cannot be inside the GridList due to ARIA and focus management requirements.
if (props.renderActionBar) {
return (
<div ref={domRef} className={style({position: 'relative', overflow: 'clip', size: 'fit'})}>
<div ref={domRef} className={UNSAFE_className + wrapperStyles(null, styles)} style={UNSAFE_style}>
{cardView}
{actionBar}
</div>
Expand Down