Skip to main content

Relation Selectors

Relation selector components provide a powerful way to select related entities in your dashboard forms. They support both single and multi-selection modes with built-in search, infinite scroll pagination, and complete TypeScript type safety.

Features

  • Real-time Search: Debounced search with customizable filters
  • Infinite Scroll: Automatic pagination loading 25 items by default
  • Single/Multi Select: Easy toggle between selection modes
  • Type Safe: Full TypeScript support with generic types
  • Customizable: Pass your own GraphQL queries and field mappings
  • Accessible: Built with Radix UI primitives

Components Overview

The relation selector system consists of three main components:

  • RelationSelector: The abstract base component that handles all core functionality
  • SingleRelationInput: Convenient wrapper for single entity selection
  • MultiRelationInput: Convenient wrapper for multiple entity selection

Basic Usage

Single Selection

src/plugins/my-plugin/dashboard/components/product-selector.tsx

Multi Selection

src/plugins/my-plugin/dashboard/components/product-multi-selector.tsx

Configuration Options

The createRelationSelectorConfig function accepts these options:

Tsx

Rich Label Display

The label prop allows you to customize how items are displayed in both the dropdown and selected item chips. This enables rich content like images, badges, and multi-line information.

Product Selector with Images and Pricing

src/plugins/my-plugin/dashboard/components/rich-product-selector.tsx

Customer Selector with Status Badges

src/plugins/my-plugin/dashboard/components/customer-selector-with-status.tsx

Advanced Examples

src/plugins/review-plugin/dashboard/components/review-selector.tsx

Asset Selector with Type Filtering

src/plugins/my-plugin/dashboard/components/image-selector.tsx

Multi-Select with Status Filtering

src/plugins/my-plugin/dashboard/components/active-customer-selector.tsx

Registration

Register your relation selector components in your dashboard extension:

src/plugins/my-plugin/dashboard/index.tsx

Built-in Configurations

The relation selector package includes pre-configured setups for common Vendure entities:

Tsx

Best Practices

Query Optimization

  1. Select only needed fields: Include only the fields you actually use to improve performance
  2. Use fragments: Create reusable fragments for consistent data fetching
  3. Optimize search filters: Use database indexes for the fields you search on
Tsx

Performance Tips

  1. Appropriate page sizes: Balance between fewer requests and faster initial loads
  2. Debounced search: The default 300ms debounce prevents excessive API calls
  3. Caching: Queries are automatically cached by TanStack Query
Tsx

Type Safety

Leverage TypeScript generics for full type safety:

Tsx

Rich Label Design

When using the label prop for custom rendering:

  1. Keep it simple: Avoid overly complex layouts that might impact performance
  2. Handle missing data: Always check for optional fields before rendering
  3. Maintain accessibility: Use proper semantic HTML and alt text for images
  4. Consider mobile: Ensure labels work well on smaller screens
Tsx

Troubleshooting

Common Issues

1. "Cannot query field X on type Query"

Error: Cannot query field "myEntities" on type "Query"

Solution: Ensure your GraphQL query field name matches your schema definition exactly.

2. Empty results despite data existing

Tsx

3. TypeScript errors with config

Tsx

Performance Issues

If you experience slow loading:

  1. Check your GraphQL query: Ensure it's optimized and uses appropriate filters
  2. Verify database indexes: Make sure searched fields are indexed
  3. Adjust page size: Try smaller page sizes for faster initial loads
  4. Optimize buildSearchFilter: Use efficient query patterns
Tsx
Was this chapter helpful?
Report Issue
Edited Feb 10, 2026·Edit this page