Skip to content

feat: add data style attributes to popover#62

Merged
luwes merged 2 commits intomainfrom
data-style-attrs
Oct 19, 2025
Merged

feat: add data style attributes to popover#62
luwes merged 2 commits intomainfrom
data-style-attrs

Conversation

@luwes
Copy link
Copy Markdown
Collaborator

@luwes luwes commented Oct 19, 2025

This pull request enhances the popover components in both the HTML and React packages to support animated transitions and improved data attribute synchronization between triggers and popups. The changes introduce a transition status state machine, update styles for smooth entrance and exit animations, and ensure that accessibility and custom data attributes are correctly propagated. These improvements make popover interactions more visually appealing and robust.

Popover Transition State and Animation Enhancements

  • Added a #transitionStatus state to MediaPopoverRoot and synchronized its value with popover visibility, enabling fine-grained control over popover transitions (media-popover.ts). [1] [2] [3]
  • Updated the popover popup styles in both HTML and React skins to animate scale, opacity, and transform properties based on transition status, providing smooth open/close effects (media-skin-default.ts, frosted/styles.ts). [1] [2]

Data Attribute Synchronization and Accessibility

  • Implemented logic in MediaPopoverTrigger to observe and copy data attributes from the trigger element to the popup, ensuring custom states and accessibility attributes are reflected in the popup (media-popover.ts).
  • In React, copied all data- attributes from the trigger element to the popup, and exposed transitionStatus in context for use in popup rendering (Popover.tsx). [1] [2]

Popover API and Behavior Improvements (React)

  • Integrated useTransitionStatus to track and provide transition status, removed conditional rendering of the popup based on open state, and updated context and trigger handling for better state management (Popover.tsx). [1] [2] [3] [4]

These changes collectively improve the user experience and maintainability of popover components by enabling smooth transitions and consistent attribute propagation.

@luwes luwes requested a review from Copilot October 19, 2025 01:50
@luwes luwes self-assigned this Oct 19, 2025
@vercel
Copy link
Copy Markdown

vercel bot commented Oct 19, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
vjs-10-demo-html Ready Ready Preview Comment Oct 19, 2025 1:50am
vjs-10-demo-react Ready Ready Preview Comment Oct 19, 2025 1:50am
vjs-10-website Ready Ready Preview Comment Oct 19, 2025 1:50am

💡 Enable Vercel Agent with $100 free credit for automated AI reviews

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request adds animated transition support and data attribute synchronization to popover components in both HTML and React packages. The changes implement a state machine for tracking transition phases, enable smooth entrance/exit animations, and ensure data attributes are properly shared between trigger and popup elements.

Key Changes:

  • Introduced transition status tracking (initial, open, close, unmounted) for controlling popover animation states
  • Added CSS transitions and data attribute-based styling for scale and opacity animations during open/close
  • Implemented data attribute synchronization from trigger to popup elements for consistent state representation

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
packages/html/html/src/components/media-popover.ts Added transition status state machine, data attribute observer, and attribute synchronization between trigger and popup
packages/html/html/src/skins/media-skin-default.ts Added CSS transitions and styling for popover animations based on data attributes
packages/react/react/src/components/Popover.tsx Integrated useTransitionStatus hook, removed conditional rendering, added data attribute copying and transition status attributes
packages/react/react/src/skins/frosted/styles.ts Added Tailwind classes for transition animations with data attribute selectors

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +170 to +201
const mutationObserver = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (mutation.type === 'attributes') {
const rootElement = this.closest('media-popover-root') as MediaPopoverRoot;
let popupElement = rootElement.querySelector('media-popover-popup') as MediaPopoverPopup;

if (!popupElement) {
const portalElement = rootElement.querySelector('media-popover-portal') as MediaPopoverPortal;
if (!portalElement) {
return;
}

popupElement = portalElement.querySelector('media-popover-popup') as MediaPopoverPopup;
if (!popupElement) {
return;
}
}

const attributeName = mutation.attributeName;
if (!attributeName || !attributeName.startsWith('data-')) {
return;
}

const attributeValue = triggerElement.getAttribute(attributeName);
if (attributeValue !== null) {
popupElement.setAttribute(attributeName, attributeValue);
} else {
popupElement.removeAttribute(attributeName);
}
}
});
});
Copy link

Copilot AI Oct 19, 2025

Choose a reason for hiding this comment

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

The MutationObserver performs repeated DOM queries for popup elements on every attribute mutation. Consider caching the popup element reference or querying it once during initialization to avoid unnecessary DOM traversals on each mutation.

Copilot uses AI. Check for mistakes.
Comment on lines +203 to +205
mutationObserver.observe(triggerElement, {
attributes: true,
});
Copy link

Copilot AI Oct 19, 2025

Choose a reason for hiding this comment

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

The MutationObserver is created but never cleaned up. Store the observer instance and call disconnect() in disconnectedCallback() to prevent memory leaks.

Copilot uses AI. Check for mistakes.
Comment on lines +161 to +168
// Copy data attributes from trigger element
const dataAttributes = triggerElement?.attributes
? Object.fromEntries(
Array.from(triggerElement.attributes)
.filter(attr => attr.name.startsWith('data-'))
.map(attr => [attr.name, attr.value]),
)
: {};
Copy link

Copilot AI Oct 19, 2025

Choose a reason for hiding this comment

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

Data attributes are extracted from the trigger element on every render. Consider memoizing this computation with useMemo() to avoid unnecessary Array operations and object creation when triggerElement hasn't changed.

Suggested change
// Copy data attributes from trigger element
const dataAttributes = triggerElement?.attributes
? Object.fromEntries(
Array.from(triggerElement.attributes)
.filter(attr => attr.name.startsWith('data-'))
.map(attr => [attr.name, attr.value]),
)
: {};
// Copy data attributes from trigger element, memoized
const dataAttributes = useMemo(() => {
return triggerElement?.attributes
? Object.fromEntries(
Array.from(triggerElement.attributes)
.filter(attr => attr.name.startsWith('data-'))
.map(attr => [attr.name, attr.value]),
)
: {};
}, [triggerElement]);

Copilot uses AI. Check for mistakes.
transform: scale(0.9) translateY(8px);
opacity: 0;
}
Copy link

Copilot AI Oct 19, 2025

Choose a reason for hiding this comment

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

Remove trailing whitespace on this empty line.

Suggested change

Copilot uses AI. Check for mistakes.
@luwes luwes merged commit 6d7325c into main Oct 19, 2025
4 checks passed
@luwes luwes deleted the data-style-attrs branch October 19, 2025 01:52
@github-actions github-actions bot mentioned this pull request Oct 24, 2025
@github-actions github-actions bot mentioned this pull request Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants