Skip to content
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

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 4 additions & 3 deletions packages/@react-spectrum/s2/src/CardView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {DOMRef, DOMRefValue, forwardRefType, Key, LoadingState} from '@react-typ
import {focusRing, style} from '../style' with {type: 'macro'};
import {getAllowedOverrides, StylesPropWithHeight, UnsafeStyles} from './style-utils' with {type: 'macro'};
import {ImageCoordinator} from './ImageCoordinator';
import {mergeStyles} from '../style/runtime';
import {Size} from '@react-stately/virtualizer';
import {useActionBarContainer} from './ActionBar';
import {useDOMRef} from '@react-spectrum/utils';
Expand Down Expand Up @@ -242,14 +243,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'}, styles) : '')}>
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure this is right, I think you still want cardViewStyles with all the states it comes with

Suggested change
className={renderProps => (!props.renderActionBar ? UNSAFE_className + cardViewStyles({...renderProps, isLoading: props.loadingState === 'loading'}, styles) : '')}>
className={renderProps => (!props.renderActionBar ? UNSAFE_className + cardViewStyles({...renderProps, isLoading: props.loadingState === 'loading'}, styles) : cardViewStyles({...renderProps, isLoading: props.loadingState === 'loading'}))}>

but you don't want either of the ways to overrides styles as provided by the user

{children}
</AriaGridList>
</ImageCoordinator>
Expand All @@ -262,7 +263,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 + mergeStyles(style({position: 'relative', overflow: 'clip', size: 'fit'}), styles)} style={UNSAFE_style}>
Copy link
Member

Choose a reason for hiding this comment

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

I think you still want to do a safe merge of styles with allowed overrides, so you may want to pull out this style like the other overridable ones style(..., getAllowedOverrides({height: true}))

{cardView}
{actionBar}
</div>
Expand Down