Skip to content

feat(select): allow HTML within options#31072

Open
thetaPC wants to merge 19 commits intonextfrom
FW-7137
Open

feat(select): allow HTML within options#31072
thetaPC wants to merge 19 commits intonextfrom
FW-7137

Conversation

@thetaPC
Copy link
Copy Markdown
Contributor

@thetaPC thetaPC commented Apr 9, 2026

Issue number: resolves #29890


What is the current behavior?

Select only allows plain text to be passed within it's options.

What is the new behavior?

ion-select-option

  • Added default slot support for custom HTML content (images, avatars, icons, etc.) when innerHTMLTemplatesEnabled is true
  • Added start and end named slots for content that appears in the overlay interface but not in the selected text
  • Added description prop for text rendered below the option label in the overlay

ion-select

  • Selected text renders HTML content from the default slot, excluding start/end slot content
  • aria-label derives plain text only from the default slot, ensuring screen readers don't read slotted or element content
  • Added CSS variables for styling media within the selected text (--select-text-media-width, --select-text-media-height, etc.)

Overlay interfaces (alert, action-sheet, select-popover, select-modal)

  • All four interfaces render rich content (start, end, description, HTML label) consistently via the shared renderOptionLabel utility
  • Public interfaces (ActionSheetButton, AlertInput, SelectPopoverOption, SelectModalOption) are unchanged — rich content fields are on internal extended interfaces (SelectActionSheetButton, SelectAlertInput, SelectOverlayOption)
  • Content is sanitized via sanitizeDOMString before DOM injection to prevent XSS

Utilities

  • Added select-option-render.tsx: shared render utility for option labels across all overlay components
  • Added getOptionContent: extracts and clones slot content from ion-select-option for overlays and selected text
  • Added getDefaultSlotPlainText — extracts plain text from the default slot, used for labels and aria

Tests

  • Added E2E tests for rich content rendering across all four interfaces (single and multiple selection)
  • Added tests for slot positioning (start/end placement verification)
  • Added tests for selected text content verification (excludes slotted content)

Does this introduce a breaking change?

  • Yes
  • No

No, developers will be able to continue using plain text for select options as usual.

Other information

Preview

@github-actions github-actions bot added the package: core @ionic/core package label Apr 9, 2026
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 9, 2026

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

Project Deployment Actions Updated (UTC)
ionic-framework Ready Ready Preview, Comment Apr 15, 2026 11:20pm

Request Review

// --------------------------------------------------

.action-sheet-button-label {
gap: 12px;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I decided to use the same value that ionic uses.

<div class="alert-button-inner">
<div class="alert-checkbox-icon">
<div class="alert-checkbox-inner"></div>
{inputs.map((i) => {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The only change is the addition of optionLabelOptions and renderOptionLabel

<div class="alert-button-inner">
<div class="alert-radio-icon">
<div class="alert-radio-inner"></div>
{inputs.map((i) => {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The only change is the addition of optionLabelOptions and renderOptionLabel

*/
this.closeModal();
}
{this.options.map((option, index) => {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The only change is the addition of optionLabelOptions and renderOptionLabel

onIonChange={(ev) => {
this.setChecked(ev);
this.callOptionHandler(ev);
return this.options.map((option, index) => {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The only change is the addition of optionLabelOptions and renderOptionLabel

/**
* Text that is placed underneath the option text to provide additional details about the option.
*/
@Prop() description?: string;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Description isn't being used here to display on the screen because ion-select-option isn't used to display the options, it's done through the respective interface. So description is passed to the interface.

Comment on lines +46 to +48
<slot name="start"></slot>
<slot></slot>
<slot name="end"></slot>
Copy link
Copy Markdown
Contributor Author

@thetaPC thetaPC Apr 10, 2026

Choose a reason for hiding this comment

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

Slots aren't being used here to display on the screen because ion-select-option isn't used to display the options, it's done through the respective interface. So slots are passed to the interface and the rendering is done with a new utility.

Even though it's not used to display here, it's still useful to include here so the docs can generate that "slots" are available for the options.

onIonChange={(ev) => {
this.setChecked(ev);
this.callOptionHandler(ev);
return options.map((option, index) => {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The only change is the addition of optionLabelOptions and renderOptionLabel

*/
this.dismissParentPopover();
}
{options.map((option, index) => {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The only change is the addition of optionLabelOptions and renderOptionLabel

@thetaPC thetaPC marked this pull request as ready for review April 11, 2026 02:06
@thetaPC thetaPC requested a review from a team as a code owner April 11, 2026 02:06
@thetaPC thetaPC requested review from BenOsodrac and ShaneK and removed request for BenOsodrac April 11, 2026 02:06
Copy link
Copy Markdown
Member

@ShaneK ShaneK left a comment

Choose a reason for hiding this comment

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

This is looking really good! Just some feedback on some things I noticed

Comment thread core/src/components/action-sheet/action-sheet-interface.ts Outdated
Comment thread core/src/components/action-sheet/action-sheet.tsx Outdated
Comment thread core/src/utils/select-option-render.tsx Outdated
Comment thread core/src/components/select/test/basic/select.e2e.ts Outdated
Comment thread core/src/components/select/select.tsx
Comment thread core/src/components/select/select.native.scss Outdated
Comment thread core/src/components/select-popover/select-popover.ionic.scss Outdated
Comment thread core/src/components/select/test/basic/index.html Outdated
// --------------------------------------------------

.action-sheet-button-label {
gap: 12px;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Based it off ionic theme

@thetaPC thetaPC requested a review from ShaneK April 16, 2026 01:06
Copy link
Copy Markdown
Member

@ShaneK ShaneK left a comment

Choose a reason for hiding this comment

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

Looks good to me! I consider these comments to be optional side quests (nits), feel free to disregard


import { sanitizeDOMString } from './sanitization';

interface RichContentOption {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

RichContentOption is declared here with id, label, startContent, endContent, description, and a separate RichContentOption in select-interface.ts has only the three content fields. Same name, different shape, no shared source. Could we export one from select-interface.ts and import it here so we can avoid drift?

<ion-select id="alert-select" label="Alert" placeholder="Select one" interface="alert">
<ion-select-option value="full" description="Choose me!">
<ion-badge slot="end">NEW</ion-badge>
<ion-avatar id="avatar" slot="start" size="large">
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

id="avatar" is repeated 35+ times on this page (lines 60, 67, 74, etc.) Duplicate IDs are invalid HTML and none of the tests query by this id. Can we drop the attribute? I assume it's just copy pasta at this point


// Render simple string label if there is no rich content to display
if (!hasRichContent && (typeof label === 'string' || !label)) {
// const Tag = useSpan ? 'span' : 'div';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Dead commented line, Tag is already declared at line 84. Can you drop this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: angular @ionic/angular package package: core @ionic/core package package: vue @ionic/vue package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants