Skip to content

[6.x] Allow addons to reuse relationship components - #15839

Open
duncanmcclean wants to merge 1 commit into
6.xfrom
relationship-ui
Open

duncanmcclean wants to merge 1 commit into
6.xfrom
relationship-ui

Conversation

@duncanmcclean

@duncanmcclean duncanmcclean commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

This pull request lets addons reuse the CMS relationship components while providing their own selection and creation UI.

Use case

The use case is Runway's new Eloquent Relationship fieldtype. For morph relationships, related records can belong to different resources—for example, a comment might belong to either a post or a video. The selector needs a resource switcher alongside search, and creation targets that aren’t necessarily blueprints.

This PR provides the generic UI hooks needed to implement that on the Runway side, without needing to copy components from cms.

Usage

The following components are now exported from @statamic/cms: RelationshipInput, RelationshipSelector, RelationshipSelectField, RelationshipCreateButton and InlineCreateForm.

RelationshipInput has a selector slot inside its existing selector stack. The slot receives select(ids) and close() callbacks. Call both to apply a selection and dismiss the stack, or only close() to cancel. Without the slot, the ordinary selector is used.

<RelationshipInput v-bind="inputProps">
    <template #selector="{ select, close }">
        <CustomSelector
            @selected="ids => { select(ids); close(); }"
            @closed="close"
        />
    </template>
</RelationshipInput>

RelationshipSelector has a toolbar slot alongside its existing search and filter controls:

<RelationshipSelector v-bind="selectorProps">
    <template #toolbar>
        <Select v-model="resource" :options="resources" />
    </template>
</RelationshipSelector>

The toolbar uses 20% of the available width on wide selectors and 40% on narrow selectors, with search filling the remainder. Selectors without custom toolbar controls keep their existing search sizing.

RelationshipCreateButton accepts a translated menuLabel, and each creation target can provide translated label and hint values alongside its url. These fall back to the existing “Choose Blueprint”, blueprint and parent_title values. Zero targets show no create control, one opens creation directly, and multiple show the menu.

RelationshipInput forwards createMenuLabel to the button; relationship fieldtypes can supply it through meta.createMenuLabel.

Screenshots

Wide selector with a 20% resource dropdown

Create menu with Posts and Videos targets


Amp thread: https://ampcode.com/threads/T-2c2291ae-edc1-4e69-8693-c58a8e0a7963

Amp-Thread-ID: https://ampcode.com/threads/T-2c2291ae-edc1-4e69-8693-c58a8e0a7963
Co-authored-by: Duncan McClean <duncan@duncanmcclean.com>
@duncanmcclean duncanmcclean changed the title [6.x] Add generic relationship UI composition [6.x] Allow addons to reuse relationship components Nov 10, 2026

This branch has not been deployed

No deployments
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