Skip to content

feat: support Shadow DOM teleport compatibility#124

Merged
hexqi merged 9 commits intoopentiny:release/v0.2.xfrom
gene9831:component/teleport
Jun 27, 2025
Merged

feat: support Shadow DOM teleport compatibility#124
hexqi merged 9 commits intoopentiny:release/v0.2.xfrom
gene9831:component/teleport

Conversation

@gene9831
Copy link
Copy Markdown
Collaborator

@gene9831 gene9831 commented Jun 23, 2025

Summary by CodeRabbit

  • New Features

    • Introduced a flexible popper component for advanced positioning and animation of floating UI elements.
    • Added a teleport utility component to enhance content placement, including support for Shadow DOM.
  • Refactor

    • Updated dropdown menu and suggestion pill components to use named trigger slots for improved slot usage and consistency.
    • Refactored dropdown menu positioning to leverage the new popper component, simplifying internal logic and enhancing reliability.
  • Bug Fixes

    • Adjusted click-outside event handling in suggestion pills to only trigger under specific conditions, preventing unnecessary events.
  • Chores

    • Cleaned up TypeScript and Vite configurations by removing unused path aliases.

gene9831 added 6 commits June 17, 2025 20:26
- Added `onItemClick`, `onClickOutside`, `onOpen`, and `onClose` event props to `SuggestionPopover` and `DropdownMenu` for improved flexibility.
- Updated `SuggestionPill` actions to utilize new event props, replacing deprecated event handling.
- Refactored `PillButtonWrapper` to support new event props for better integration with suggestion actions.
- Improved handling of click events and visibility toggling in `SuggestionPills` and related components.
…port

- Introduced a `trigger` slot in `DropdownMenu` and `PillButtonWrapper` components to allow custom trigger elements.
- Refactored event handling for dropdown menus to utilize a centralized `closeAllDropdownMenus` function for improved code clarity.
- Enhanced the `DropdownMenu` component to support teleporting the dropdown menu to the trigger element's position.
- Updated related demo files to reflect the new slot structure for better usability.
…components

- Changed item IDs in `pills-popper-config.vue` to start from 2 for better uniqueness.
- Refactored visibility logic in `index.vue` to simplify conditions for showing static and floating items based on button visibility and state.
- Removed unnecessary gap calculation function and replaced it with a fixed gap value for consistency.
…ity handling

- Introduced a button in `pills-popper-config.vue` to allow users to dynamically add items to the suggestion list.
- Implemented a `closeAllPopper` function to streamline the visibility management of suggestion items.
- Enhanced click handling to ensure proper visibility toggling when interacting with the new button.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 23, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This update introduces a new BasePopper component to encapsulate popper positioning and teleportation logic, refactors the DropdownMenu component to delegate positioning to BasePopper, and updates all dropdown trigger usages to use explicit trigger slots. A new teleport wrapper component is added, and related configuration and typings are adjusted accordingly.

Changes

Files/Groups Change Summary
packages/components/src/base-popper/index.ts, index.vue Added new BasePopper Vue component for popper positioning, teleportation, and trigger/content slot handling.
packages/components/src/teleport/index.ts, index.vue Added new teleport wrapper component TrTeleport with flexible target resolution.
packages/components/src/dropdown-menu/index.vue Refactored to use TrBasePopper for positioning; removed manual bounding logic and topOffset prop.
packages/components/src/dropdown-menu/index.type.ts Removed topOffset prop; changed slot signature from default to trigger.
docs/demos/dropdown-menu/basic.vue, docs/demos/suggestion/pills-popper.vue,
packages/components/src/suggestion-pills/components/PillButtonWrapper.vue Updated dropdown trigger usage to use named trigger slot instead of direct child.
packages/components/src/suggestion-pills/index.vue Changed click-outside event emission to only trigger when showAll is true.
packages/components/tsconfig.json, vite.config.ts Removed baseUrl, paths from TypeScript config and alias from Vite config.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Trigger (slot)
    participant TrBasePopper
    participant TrTeleport
    participant PopperContent (slot)

    User->>Trigger (slot): Clicks trigger element
    Trigger (slot)->>TrBasePopper: Receives trigger event
    TrBasePopper->>TrBasePopper: Computes position & visibility
    TrBasePopper->>TrTeleport: Teleports popper content to target
    TrTeleport->>PopperContent (slot): Renders dropdown menu
    User->>Trigger (slot): Clicks outside
    TrBasePopper->>TrBasePopper: Hides popper
Loading

Poem

In the meadow, menus pop and float,
With teleport magic, across the moat.
Slots for triggers, so neat and clear,
The popper’s position brings dropdowns near.
With every hop, the code refines—
A rabbit’s joy in tidy lines!
🐇✨

✨ Finishing Touches
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in Comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

- Added a new `BasePopper` component to manage popper positioning and visibility.
- Refactored `DropdownMenu` to utilize `BasePopper` for improved structure and event handling.
- Removed unused properties and simplified the dropdown menu's implementation.
- Enhanced styling and slot support for better customization.
@gene9831 gene9831 changed the title feat: enhance event handling in suggestion components feat: support Shadow DOM teleport compatibility Jun 25, 2025
@gene9831 gene9831 marked this pull request as ready for review June 25, 2025 06:52
@gene9831
Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 25, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
packages/components/src/base-popper/index.vue (3)

1-1: Consider removing the ESLint disable comment.

The @typescript-eslint/no-explicit-any disable comment covers the entire file. Consider using more specific type annotations instead of any to improve type safety.


116-151: Sophisticated positioning logic with viewport constraint handling.

The positioning implementation is well thought out:

  • Uses CSS clamp() for elegant viewport boundary constraints
  • Handles all placement combinations correctly
  • Properly accounts for both main and cross axis offsets

One minor suggestion for line 138 - the bottom calculation could be simplified for better readability.

Consider extracting the complex calculation on line 138 into a computed property or helper function for better readability:

  if (placement.includes('bottom')) {
-   set('bottom', `calc(100% - ${toCssUnit(bottom.value + popperHeight.value + resolvedOffset.value.mainAxis)})`)
+   const bottomPosition = bottom.value + popperHeight.value + resolvedOffset.value.mainAxis
+   set('bottom', `calc(100% - ${toCssUnit(bottomPosition)})`)
  }

172-186: Consider adding ARIA attributes for accessibility.

While the component handles positioning well, it lacks accessibility attributes that would help screen readers understand the relationship between triggers and popper content.

Consider adding ARIA attributes to establish the relationship between triggers and content:

  <component
    v-for="(vnode, index) in renderedTriggerVNodes"
    :key="(vnode as VNode).key ?? index"
    :is="vnode"
    :ref="(el: unknown) => setRefs(el, index)"
    v-bind="indexedEventHandlers[index]"
+   :aria-expanded="show"
+   :aria-controls="show ? `popper-${$.uid}` : undefined"
  />
  <TrTeleport :anchor="unrefElement(triggerRef)">
    <Transition v-bind="transitionProps">
-     <div v-if="show" class="tr-base-popper" ref="popperRef" :style="popperStyles" v-bind="$attrs">
+     <div v-if="show" :id="`popper-${$.uid}`" class="tr-base-popper" ref="popperRef" :style="popperStyles" v-bind="$attrs" role="tooltip">
        <slot name="content" />
      </div>
    </Transition>
  </TrTeleport>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 02739ac and 62209af.

📒 Files selected for processing (12)
  • docs/demos/dropdown-menu/basic.vue (2 hunks)
  • docs/demos/suggestion/pills-popper.vue (1 hunks)
  • packages/components/src/base-popper/index.ts (1 hunks)
  • packages/components/src/base-popper/index.vue (1 hunks)
  • packages/components/src/dropdown-menu/index.type.ts (2 hunks)
  • packages/components/src/dropdown-menu/index.vue (5 hunks)
  • packages/components/src/suggestion-pills/components/PillButtonWrapper.vue (1 hunks)
  • packages/components/src/suggestion-pills/index.vue (1 hunks)
  • packages/components/src/teleport/index.ts (1 hunks)
  • packages/components/src/teleport/index.vue (1 hunks)
  • packages/components/tsconfig.json (0 hunks)
  • packages/components/vite.config.ts (0 hunks)
💤 Files with no reviewable changes (2)
  • packages/components/tsconfig.json
  • packages/components/vite.config.ts
🔇 Additional comments (11)
packages/components/src/teleport/index.ts (1)

1-1: Verify the referenced Vue component exists.

The export pattern follows standard conventions for Vue component libraries. However, ensure that ./index.vue exists and properly implements the TrTeleport component.

#!/bin/bash
# Description: Verify that the TrTeleport Vue component exists and is properly implemented
# Expected: Find the index.vue file and verify it's a valid Vue component

# Check if the Vue component file exists
fd -t f "index.vue" packages/components/src/teleport/

# If found, examine the component structure
if [ -f "packages/components/src/teleport/index.vue" ]; then
  echo "=== TrTeleport Component Content ==="
  cat packages/components/src/teleport/index.vue
else
  echo "ERROR: index.vue not found in teleport directory"
fi
packages/components/src/base-popper/index.ts (1)

1-5: Component export pattern looks good.

The implementation follows standard Vue component library patterns:

  • Proper import/export structure
  • Consistent naming convention with 'Tr' prefix
  • Explicit component name assignment for debugging
#!/bin/bash
# Description: Verify that the BasePopper Vue component exists and follows expected patterns
# Expected: Find the index.vue file and verify it's a valid Vue component with proper structure

# Check if the Vue component file exists
if [ -f "packages/components/src/base-popper/index.vue" ]; then
  echo "=== BasePopper Component Found ==="
  # Check for basic Vue component structure
  head -20 packages/components/src/base-popper/index.vue
  echo "..."
  echo "=== Component structure analysis ==="
  rg -A 5 -B 5 "<template|<script|export default" packages/components/src/base-popper/index.vue
else
  echo "ERROR: index.vue not found in base-popper directory"
fi
docs/demos/dropdown-menu/basic.vue (1)

3-5: Consistent trigger slot implementation across different trigger modes.

The updates correctly implement the new trigger slot pattern for both automatic and manual trigger modes. The slot usage is consistent and maintains proper event handling for the manual trigger case.

Also applies to: 15-17

packages/components/src/suggestion-pills/components/PillButtonWrapper.vue (1)

37-39: Precise and targeted API migration.

The change correctly updates only the dropdown menu case while preserving:

  • Conditional rendering logic for different action types
  • Event handling (@pointerup emission)
  • Component props and styling

This demonstrates careful attention to the component's existing behavior patterns.

packages/components/src/suggestion-pills/index.vue (1)

117-120: Good conditional check for click-outside event emission.

The addition of the showAll.value check ensures that the click-outside event is only emitted when the component is in the expanded state. This prevents unnecessary event propagation when the component is collapsed.

packages/components/src/dropdown-menu/index.type.ts (1)

1-2: Type definitions correctly updated for the new slot-based trigger pattern.

The changes properly reflect the dropdown menu's new architecture:

  • Import of VNode type for proper slot typing
  • Slot renamed from default to trigger with appropriate VNode return type

These align well with the component's refactor to use TrBasePopper.

Also applies to: 23-24

packages/components/src/teleport/index.vue (1)

1-26: Well-implemented teleport wrapper with Shadow DOM support.

This component elegantly handles Shadow DOM compatibility by:

  • Detecting when the anchor element is within a Shadow DOM tree
  • Automatically teleporting to the ShadowRoot when appropriate
  • Falling back to document.body for regular DOM contexts

The implementation is clean and focused on its single responsibility.

packages/components/src/dropdown-menu/index.vue (2)

1-84: Excellent refactor to use TrBasePopper for positioning logic.

The refactor successfully:

  • Delegates complex positioning calculations to a dedicated component
  • Simplifies the dropdown menu to focus on its core functionality
  • Maintains all existing behavior while improving maintainability
  • Properly handles manual vs automatic show state control

The use of computed refs to access basePopper's internal elements is a clean approach.


86-136: Styles properly organized for the refactored component.

Good separation of:

  • Non-scoped styles for the popper container (transition animations)
  • Scoped styles for the dropdown menu list items

The transition timing and visual styling are preserved from the original implementation.

packages/components/src/base-popper/index.vue (2)

44-84: Robust trigger reference handling with good edge case coverage.

The implementation correctly:

  • Handles Fragment nodes from v-for loops
  • Supports both Vue component instances and native DOM elements
  • Provides helpful console warnings for invalid trigger types
  • Manages dynamic trigger counts with proper cleanup

85-99: Clean implementation of indexed event handlers.

The event handler wrapping correctly:

  • Preserves the original event handler pattern (onXxx)
  • Passes the trigger index as the last argument
  • Only wraps actual functions

This enables proper multi-trigger support.

Comment thread docs/demos/suggestion/pills-popper.vue
gene9831 added 2 commits June 26, 2025 15:27
- Replaced the custom `TrTeleport` component with the new `Teleport` functionality in `BasePopper` for improved performance and simplicity.
- Introduced a new `useTeleportTarget` composable to manage teleport target selection based on the reference element.
- Refactored `DropdownMenu` styles to reset padding and margin for better layout control.
- Removed deprecated `teleport` component files to streamline the codebase.
- Removed unused ComputedRef type from the `useTeleportTarget` function signature for cleaner code.
- Streamlined the function definition to enhance readability and maintainability.
@hexqi hexqi merged commit 382d3bc into opentiny:release/v0.2.x Jun 27, 2025
@gene9831 gene9831 deleted the component/teleport branch June 27, 2025 02:20
gene9831 added a commit to gene9831/tiny-robot that referenced this pull request Jul 3, 2025
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