Skip to content

Add appendOption and replaceOptions to drive the option list - #19

Merged
ulsyemr merged 1 commit into
MehmetCelik4:mainfrom
ulsyemr:feat/option-list-api
Aug 17, 2026
Merged

Add appendOption and replaceOptions to drive the option list#19
ulsyemr merged 1 commit into
MehmetCelik4:mainfrom
ulsyemr:feat/option-list-api

Conversation

@ulsyemr

@ulsyemr ulsyemr commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

Why

Host apps that load options outside the Turbo Stream flow have no way to add or replace them. optionElement gave them the markup; this gives them the list.

What

select.appendOption({ id: "9", label: "Item C" })

select.replaceOptions(options)                     // swap the list, keep the selection
select.replaceOptions(options, { selected: "7" })  // swap it and set the value
select.replaceOptions(options, { selected: null }) // swap it and clear the value
select.replaceOptions(options, { silent: false })  // broadcast the resulting value

Both take options in the option contract shape and render them through optionElement, so they carry the host's class map.

appendOption adds one option to the end and does nothing if that id is already present. It does not select it — that is addOption, which belongs to Add Mode.

replaceOptions swaps the whole list. Leaving selected out keeps the current selection even when the new list no longer contains it — the common case after a remote search, where the selected record can fall outside the page of results. Passing selected assigns it with setValue semantics, null included.

It is silent by default, unlike setValue: replacing a list is not a value change and should not cascade to dependent fields on its own.

@ulsyemr
ulsyemr merged commit 5c70609 into MehmetCelik4:main Aug 17, 2026
1 check passed
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.

1 participant