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

Merged
merged 7 commits into from
Feb 27, 2025

Conversation

yihuiliao
Copy link
Member

Closes #7684

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

🧢 Your Project:

@yihuiliao yihuiliao marked this pull request as ready for review February 20, 2025 01:20
@rspbot
Copy link

rspbot commented Feb 20, 2025

@rspbot
Copy link

rspbot commented Feb 20, 2025

@rspbot
Copy link

rspbot commented Feb 21, 2025

@rspbot
Copy link

rspbot commented Feb 21, 2025

@rspbot
Copy link

rspbot commented Feb 21, 2025

// 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

@@ -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}))

@rspbot
Copy link

rspbot commented Feb 26, 2025

@rspbot
Copy link

rspbot commented Feb 26, 2025

## API Changes

react-aria-components

/react-aria-components:Menu

 Menu <T extends {}> {
   aria-describedby?: string
   aria-details?: string
   aria-label?: string
   aria-labelledby?: string
   autoFocus?: boolean | FocusStrategy
   children?: ReactNode | ({}) => ReactNode
-  className?: string | ((MenuRenderProps & {
-    defaultClassName: string | undefined
-})) => string
+  className?: string
   defaultSelectedKeys?: 'all' | Iterable<Key>
   dependencies?: ReadonlyArray<any>
   disabledKeys?: Iterable<Key>
   disallowEmptySelection?: boolean
   id?: string
   items?: Iterable<T>
   onAction?: (Key) => void
   onClose?: () => void
   onScroll?: (UIEvent<Element>) => void
   onSelectionChange?: (Selection) => void
-  renderEmptyState?: () => ReactNode
   selectedKeys?: 'all' | Iterable<Key>
   selectionMode?: SelectionMode
   shouldFocusWrap?: boolean
   slot?: string | null
-  style?: CSSProperties | ((MenuRenderProps & {
-    defaultStyle: CSSProperties
-})) => CSSProperties | undefined
+  style?: CSSProperties
 }

/react-aria-components:MenuProps

 MenuProps <T> {
   aria-describedby?: string
   aria-details?: string
   aria-label?: string
   aria-labelledby?: string
   autoFocus?: boolean | FocusStrategy
   children?: ReactNode | (T) => ReactNode
-  className?: string | ((MenuRenderProps & {
-    defaultClassName: string | undefined
-})) => string
+  className?: string
   defaultSelectedKeys?: 'all' | Iterable<Key>
   dependencies?: ReadonlyArray<any>
   disabledKeys?: Iterable<Key>
   disallowEmptySelection?: boolean
   id?: string
   items?: Iterable<T>
   onAction?: (Key) => void
   onClose?: () => void
   onScroll?: (UIEvent<Element>) => void
   onSelectionChange?: (Selection) => void
-  renderEmptyState?: () => ReactNode
   selectedKeys?: 'all' | Iterable<Key>
   selectionMode?: SelectionMode
   shouldFocusWrap?: boolean
   slot?: string | null
-  style?: CSSProperties | ((MenuRenderProps & {
-    defaultStyle: CSSProperties
-})) => CSSProperties | undefined
+  style?: CSSProperties
 }

/react-aria-components:NumberFieldRenderProps

 NumberFieldRenderProps {
   isDisabled: boolean
   isInvalid: boolean
-  isRequired: boolean
   state: NumberFieldState
 }

@react-spectrum/s2

/@react-spectrum/s2:Menu

 Menu <T extends {}> {
   UNSAFE_className?: string
   UNSAFE_style?: CSSProperties
   aria-describedby?: string
   aria-details?: string
   aria-label?: string
   aria-labelledby?: string
   autoFocus?: boolean | FocusStrategy
   children: ReactNode | ({}) => ReactNode
   defaultSelectedKeys?: 'all' | Iterable<Key>
   disabledKeys?: Iterable<Key>
   disallowEmptySelection?: boolean
   hideLinkOutIcon?: boolean
   id?: string
   items?: Iterable<T>
   onAction?: (Key) => void
   onClose?: () => void
   onScroll?: (UIEvent<Element>) => void
   onSelectionChange?: (Selection) => void
-  renderEmptyState?: () => ReactNode
   selectedKeys?: 'all' | Iterable<Key>
   selectionMode?: SelectionMode
   shouldFocusWrap?: boolean
   size?: 'S' | 'M' | 'L' | 'XL' = 'M'
   styles?: StylesProp
 }

/@react-spectrum/s2:TreeViewItem

-TreeViewItem {
+TreeViewItem <T extends {}> {
   aria-label?: string
+  childItems?: Iterable<{}>
   children: ReactNode
   download?: boolean | string
   hasChildItems?: boolean
   href?: Href
   id?: Key
   isDisabled?: boolean
   onAction?: () => void
   onHoverChange?: (boolean) => void
   onHoverEnd?: (HoverEvent) => void
   onHoverStart?: (HoverEvent) => void
   ping?: string
   referrerPolicy?: HTMLAttributeReferrerPolicy
   rel?: string
   routerOptions?: RouterOptions
   target?: HTMLAttributeAnchorTarget
   textValue: string
   value?: T
 }

/@react-spectrum/s2:MenuProps

 MenuProps <T> {
   UNSAFE_className?: string
   UNSAFE_style?: CSSProperties
   aria-describedby?: string
   aria-details?: string
   aria-label?: string
   aria-labelledby?: string
   autoFocus?: boolean | FocusStrategy
   children: ReactNode | (T) => ReactNode
   defaultSelectedKeys?: 'all' | Iterable<Key>
   disabledKeys?: Iterable<Key>
   disallowEmptySelection?: boolean
   hideLinkOutIcon?: boolean
   id?: string
   items?: Iterable<T>
   onAction?: (Key) => void
   onClose?: () => void
   onScroll?: (UIEvent<Element>) => void
   onSelectionChange?: (Selection) => void
-  renderEmptyState?: () => ReactNode
   selectedKeys?: 'all' | Iterable<Key>
   selectionMode?: SelectionMode
   shouldFocusWrap?: boolean
   size?: 'S' | 'M' | 'L' | 'XL' = 'M'
   styles?: StylesProp
 }

/@react-spectrum/s2:TreeViewItemProps

-TreeViewItemProps {
+TreeViewItemProps <T extends {} = {}> {
   aria-label?: string
+  childItems?: Iterable<{}>
   children: ReactNode
   download?: boolean | string
   hasChildItems?: boolean
   href?: Href
   id?: Key
   isDisabled?: boolean
   onAction?: () => void
   onHoverChange?: (boolean) => void
   onHoverEnd?: (HoverEvent) => void
   onHoverStart?: (HoverEvent) => void
   ping?: string
   referrerPolicy?: HTMLAttributeReferrerPolicy
   rel?: string
   routerOptions?: RouterOptions
   target?: HTMLAttributeAnchorTarget
   textValue: string
   value?: T
 }

@react-spectrum/style-macro-s1

/@react-spectrum/style-macro-s1:focusRing

-focusRing {
-  returnVal: undefined
-}

@react-spectrum/tree

/@react-spectrum/tree:TreeViewItem

-TreeViewItem {
+TreeViewItem <T extends {}> {
   aria-label?: string
+  childItems?: Iterable<{}>
   children: ReactNode
   download?: boolean | string
   hasChildItems?: boolean
   href?: Href
   id?: Key
   isDisabled?: boolean
   onAction?: () => void
   ping?: string
   referrerPolicy?: HTMLAttributeReferrerPolicy
   rel?: string
   routerOptions?: RouterOptions
   target?: HTMLAttributeAnchorTarget
   textValue: string
 }

/@react-spectrum/tree:SpectrumTreeViewItemProps

-SpectrumTreeViewItemProps {
+SpectrumTreeViewItemProps <T extends {} = {}> {
   aria-label?: string
+  childItems?: Iterable<{}>
   children: ReactNode
   download?: boolean | string
   hasChildItems?: boolean
   href?: Href
   id?: Key
   isDisabled?: boolean
   onAction?: () => void
   ping?: string
   referrerPolicy?: HTMLAttributeReferrerPolicy
   rel?: string
   routerOptions?: RouterOptions
   target?: HTMLAttributeAnchorTarget
   textValue: string
 }

@yihuiliao yihuiliao enabled auto-merge February 27, 2025 00:54
Copy link
Member

@LFDanLu LFDanLu left a comment

Choose a reason for hiding this comment

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

LGTM, but would be nice to have a story that applies styles to a CardView when an actionbar is provided just to make testing easier. I tested locally and didn't realize that the ActionBar's CardView doesn't actually use the styles provided and thought it wasn't working haha

@yihuiliao yihuiliao added this pull request to the merge queue Feb 27, 2025
github-merge-queue bot pushed a commit that referenced this pull request Feb 27, 2025
* fix(s2): apply styling to cardview when using an action bar

* remove comment

* don't apply styles twice

* add styles back in

* fixes from review
@snowystinger snowystinger removed this pull request from the merge queue due to a manual request Feb 27, 2025
@snowystinger snowystinger added this pull request to the merge queue Feb 27, 2025
Merged via the queue into main with commit f90f489 Feb 27, 2025
30 checks passed
@snowystinger snowystinger deleted the style-cardview branch February 27, 2025 01:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Styling not applied to CardView wrapper when using an action bar
4 participants