Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(HoverCard): theme target + consumer style forwarding (#4419)

Cindy Zhanga451fcb57d7c
diff --git a/.changeset/hovercard-theme-target.md b/.changeset/hovercard-theme-target.md
new file mode 100644
index 0000000000..775e7e5c75
--- /dev/null
+++ b/.changeset/hovercard-theme-target.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] HoverCard: move themeProps className to the layer container (where bg/radius/shadow live) so themes can target the visual surface. Forward consumer xstyle/className/style to that same layer container so surface customization lands next to the theme class, instead of silently dropping them.
+
+@cixzhang
diff --git a/packages/core/src/HoverCard/useHoverCard.tsx b/packages/core/src/HoverCard/useHoverCard.tsx
index 6942d0abb3..cbedb4c091 100644
--- a/packages/core/src/HoverCard/useHoverCard.tsx
+++ b/packages/core/src/HoverCard/useHoverCard.tsx
@@ -34,7 +34,6 @@ import {
radiusVars,
spacingVars,
} from '../theme/tokens.stylex';
-import {mergeProps} from '../utils';
import {themeProps} from '../utils/themeProps';
const styles = stylex.create({
@@ -469,6 +468,7 @@ export function useHoverCard(options: HoverCardOptions = {}): HoverCardReturn {
props?: Omit<ContextRenderProps, 'positioning'>,
): ReactNode => {
const renderPlacement = props?.placement ?? placement;
+ const themeClassName = themeProps('hovercard').className;
const renderProps = {
placement: renderPlacement,
alignment: props?.alignment ?? alignment,
@@ -477,7 +477,19 @@ export function useHoverCard(options: HoverCardOptions = {}): HoverCardReturn {
// are non-modal, so group is honest semantics without a name.
role: label ? 'dialog' : 'group',
'aria-label': label || undefined,
- xstyle: [popoverXstyle, layerAnimations[renderPlacement]],
+ // Consumer surface style props land on the layer container — the
+ // themed surface (bg/radius/shadow) where the theme class lives — so
+ // customizing the card targets the same element as the theme. The inner
+ // span keeps `styles.content` for padding.
+ xstyle: [
+ popoverXstyle,
+ layerAnimations[renderPlacement],
+ props?.xstyle,
+ ],
+ className: props?.className
+ ? `${themeClassName} ${props.className}`
+ : themeClassName,
+ style: props?.style,
// Render the layer as inline-safe phrasing markup so HoverCard stays
// valid (and hydration-stable) inside inline contexts like a `<p>`.
as: 'span' as const,
@@ -485,7 +497,7 @@ export function useHoverCard(options: HoverCardOptions = {}): HoverCardReturn {
return layer.render(
<span
- {...mergeProps(themeProps('hovercard'), stylex.props(styles.content))}
+ {...stylex.props(styles.content)}
onMouseEnter={() => {
isHoveringContentRef.current = true;
clearTimeouts();