-
Notifications
You must be signed in to change notification settings - Fork 3.2k
docs(select): add new section on rich content options #4512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: major-9.0
Are you sure you want to change the base?
Changes from all commits
f4ea004
ec02fee
004228d
6f73533
ca1f07f
3396381
c3e75e5
6848c26
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -201,6 +201,20 @@ import StartEndSlots from '@site/static/usage/v9/select/start-end-slots/index.md | |||||
|
|
||||||
| <StartEndSlots /> | ||||||
|
|
||||||
| ## Rich Content Options | ||||||
|
|
||||||
| :::important | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not part of this PR but personal question: Do you think purple is appropriate for |
||||||
| Rich content in select options is disabled by default. Set [`innerHTMLTemplatesEnabled`](/docs/developing/config#ionicconfig) to `true` in your [global Ionic config](/docs/developing/config#global-config). Markup inside options is treated as plain text when it is disabled. Refer to [Security](/docs/techniques/security.md) for sanitization guidance when enabling custom HTML. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By adding
Suggested change
|
||||||
| ::: | ||||||
|
|
||||||
| In addition to single text labels, [Select Options](./select-option.md) can include HTML rich content in the select interface. Elements added inside of an option without a named slot will go into the default label. The `start` and `end` slots will place elements on either side of the default slot. The `description` attribute can be used for additional supporting text displayed under the label. | ||||||
|
|
||||||
| This is separate from [Start and End Slots](#start-and-end-slots) on `ion-select`, which decorate the closed field. The rich content options display in the interface after opening the select. | ||||||
|
|
||||||
| import RichContentOptions from '@site/static/usage/v9/select/rich-content-options/index.md'; | ||||||
|
|
||||||
| <RichContentOptions /> | ||||||
|
|
||||||
| ## Customization | ||||||
|
|
||||||
| There are two units that make up the Select component and each need to be styled separately. The `ion-select` element is represented on the view by the selected value(s), or placeholder if there is none, and dropdown icon. The interface, which is defined in the [Interfaces](#interfaces) section above, is the dialog that opens when clicking on the `ion-select`. The interface contains all of the options defined by adding `ion-select-option` elements. The following sections will go over the differences between styling these. | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -61,7 +61,7 @@ To learn more about the security recommendations for binding to directives such | |||||
|
|
||||||
| ## Enabling Custom HTML Parsing via `innerHTML` | ||||||
|
|
||||||
| `ion-alert`, `ion-infinite-scroll-content`, `ion-loading`, `ion-refresher-content`, and `ion-toast` can accept custom HTML as strings for certain properties. These strings are added to the DOM using `innerHTML` and must be properly sanitized by the developer. This behavior is disabled by default which means values passed to the affected components will always be interpreted as plaintext. Developers can enable this custom HTML behavior by setting `innerHTMLTemplatesEnabled: true` in the [IonicConfig](../developing/config#ionicconfig). | ||||||
| `ion-alert`, `ion-infinite-scroll-content`, `ion-loading`, `ion-refresher-content`, `ion-select-option`, and `ion-toast` can accept custom HTML as strings for certain properties. These strings are added to the DOM using `innerHTML` and must be properly sanitized by the developer. This behavior is disabled by default which means values passed to the affected components will always be interpreted as plaintext. Developers can enable this custom HTML behavior by setting `innerHTMLTemplatesEnabled: true` in the [IonicConfig](../developing/config#ionicconfig). | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By adding
Suggested change
|
||||||
|
|
||||||
| ## Ejecting from the built-in sanitizer | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -71,3 +71,11 @@ To opt-out of this behavior, set `includeIonContent={false}` to disable this wra | |||||
| ```tsx | ||||||
| <Playground includeIonContent={false} /> | ||||||
| ``` | ||||||
|
|
||||||
| ## Ionic Config | ||||||
|
|
||||||
| Pass an [IonicConfig](/docs/developing/config#ionicconfig) object so generated StackBlitz projects bootstrap with the same settings. This is merged with the active preview `mode` when opening the editor. Only string, number, and boolean values are injected into generated code: | ||||||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I chose this rather than adding an entire file for each framework to pass the config like Vue but if we prefer that approach I can revert this.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By adding
Suggested change
|
||||||
|
|
||||||
| ```tsx | ||||||
| <Playground version="9" ionicConfig={{ innerHTMLTemplatesEnabled: true }} /> | ||||||
| ``` | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ import useBaseUrl from '@docusaurus/useBaseUrl'; | |
| import './playground.css'; | ||
| import { EditorOptions, openAngularEditor, openHtmlEditor, openReactEditor, openVueEditor } from './stackblitz.utils'; | ||
| import { useColorMode } from '@docusaurus/theme-common'; | ||
| import { ConsoleItem, Mode, UsageTarget } from './playground.types'; | ||
| import { ConsoleItem, IonicConfig, Mode, UsageTarget } from './playground.types'; | ||
|
|
||
| import Tippy from '@tippyjs/react'; | ||
| import 'tippy.js/dist/tippy.css'; | ||
|
|
@@ -120,8 +120,14 @@ interface UsageTargetOptions { | |
| * @param description Optional description of the generated playground example. Specify to customize the StackBlitz description. | ||
| * @param src The absolute path to the playground demo. For example: `/usage/button/basic/demo.html` | ||
| * @param size The height of the playground. Supports `xsmall`, `small`, `medium`, `large`, 'xlarge' or any string value. | ||
| * @param mode Restricts the playground to a single specified mode. Acceptable values are: `ios` or `md`. | ||
| * @param devicePreview `true` if the playground example should render in a device frame (iOS/MD). | ||
| * @param showConsole `true` if the playground should render a console UI that reflects console logs, warnings, and errors. | ||
| * @param includeIonContent Whether to include the `ion-app` and `ion-content` elements in the generated StackBlitz example. | ||
| * @param ionicConfig Ionic config values to inject into generated StackBlitz examples. | ||
| * @param version The major version of Ionic to use in the generated StackBlitz example. | ||
| * @param defaultFramework The framework to select by default when no user preference is stored. | ||
| * @returns The generated StackBlitz example. | ||
| */ | ||
| export default function Playground({ | ||
| code, | ||
|
|
@@ -133,6 +139,7 @@ export default function Playground({ | |
| devicePreview, | ||
| showConsole, | ||
| includeIonContent = true, | ||
| ionicConfig, | ||
| version, | ||
| defaultFramework, | ||
| }: { | ||
|
|
@@ -150,6 +157,12 @@ export default function Playground({ | |
| devicePreview?: boolean; | ||
| showConsole?: boolean; | ||
| includeIonContent: boolean; | ||
| /** | ||
| * Ionic config values to inject into generated StackBlitz examples. For | ||
| * example: `{ innerHTMLTemplatesEnabled: true }`. Merges with the active | ||
| * preview `mode` when opening the editor. | ||
| */ | ||
| ionicConfig?: IonicConfig; | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I decided to add this as a config object instead of adding
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't mind this, but my concern is that it might be confusing for devs who are reviewing the demos. Some might not realize the important admonition and only copy/paste code. They'll probably think that the select option has a bug. If we included I don't feel strongly about this since:
|
||
| /** | ||
| * The major version of Ionic to use in the generated StackBlitz examples. | ||
| * This will also load assets for StackBlitz from the specified version directory. | ||
|
|
@@ -551,6 +564,7 @@ export default function Playground({ | |
| title, | ||
| description, | ||
| includeIonContent, | ||
| ionicConfig, | ||
| mode: isIOS ? 'ios' : 'md', | ||
| version, | ||
| }; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,3 +14,9 @@ export interface ConsoleItem { | |
| type: 'log' | 'warning' | 'error'; | ||
| message: string; | ||
| } | ||
|
|
||
| /** | ||
| * Ionic app configuration. See [IonicConfig](/docs/developing/config#ionicconfig). | ||
| * Playground only injects serializable values (string, number, boolean) into StackBlitz. | ||
| */ | ||
| export type IonicConfig = Record<string, unknown>; | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was going to import the type from Ionic but then we would have a dependency on |
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should also mention that a selected text will strip out the HTML to only provide plain text. Also start, end slots and descriptions are not included.