docs(select): add new section on rich content options#4512
docs(select): add new section on rich content options#4512brandyscarney wants to merge 8 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| * example: `{ innerHTMLTemplatesEnabled: true }`. Merges with the active | ||
| * preview `mode` when opening the editor. | ||
| */ | ||
| ionicConfig?: IonicConfig; |
There was a problem hiding this comment.
I decided to add this as a config object instead of adding innerHTMLTemplatesEnabled as a boolean because this will allow us to enhance the Config documentation if desired by adding playgrounds passing different config options.
There was a problem hiding this comment.
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 innerHTMLTemplatesEnabled within the code then we can avoid this.
I don't feel strongly about this since:
- you do have that admonition
- the demos only provide the bare minimal (meaning we don't show files like
App.tsxto showcase config changes)
| * 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>; |
There was a problem hiding this comment.
I was going to import the type from Ionic but then we would have a dependency on @ionic/core and I don't know if we want that.
|
|
||
| ## 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: |
There was a problem hiding this comment.
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.
| const formatInterfaceLabel = (selectInterface) => { | ||
| return selectInterface | ||
| .split('-') | ||
| .map((word) => word.charAt(0).toUpperCase() + word.slice(1)) | ||
| .join(' '); | ||
| }; | ||
|
|
||
| /* Dynamically create the different Select components */ | ||
| const selectInterfaces = ['alert', 'action-sheet', 'modal', 'popover']; |
There was a problem hiding this comment.
Originally I defined the interface array like this:
const selectInterfaces = [{
label: 'Alert',
value: 'alert',
}, {
label: 'Action Sheet',
value: 'action-sheet',
}, {
label: 'Modal',
value: 'modal',
}, {
label: 'Popover',
value: 'popover',
}];but I removed it in favor of using the single string and converting it to the label. If we think this is too much for the demo, I can go back to the object array.
| /* The interfaceOptions property is for demonstration purposes only. */ | ||
| /* It is not required for the rich options to work. */ | ||
| select.interfaceOptions = { | ||
| header: 'Travel mode', | ||
| }; |
There was a problem hiding this comment.
This is just to make the demo look nicer but can be removed if desired.
thetaPC
left a comment
There was a problem hiding this comment.
LGTM, minor suggestions!
Thank you for updating the Playground docs!
|
|
||
| <StartEndSlots /> | ||
|
|
||
| ## Rich Content Options |
There was a problem hiding this comment.
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.
|
|
||
| ## Rich Content Options | ||
|
|
||
| :::important |
There was a problem hiding this comment.
Not part of this PR but personal question: Do you think purple is appropriate for important?
| ## Rich Content Options | ||
|
|
||
| :::important | ||
| 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. |
There was a problem hiding this comment.
By adding .md, it will be easier to migrate the files later from .md to .mdx.
| 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. | |
| Rich content in select options is disabled by default. Set [`innerHTMLTemplatesEnabled`](/docs/developing/config.md#ionicconfig) to `true` in your [global Ionic config](/docs/developing/config.md#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. |
| ## 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). |
There was a problem hiding this comment.
By adding .md, it will be easier to migrate the files later from .md to .mdx. Might as well add it since we're here.
| `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). | |
| `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.md#ionicconfig). |
| * example: `{ innerHTMLTemplatesEnabled: true }`. Merges with the active | ||
| * preview `mode` when opening the editor. | ||
| */ | ||
| ionicConfig?: IonicConfig; |
There was a problem hiding this comment.
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 innerHTMLTemplatesEnabled within the code then we can avoid this.
I don't feel strongly about this since:
- you do have that admonition
- the demos only provide the bare minimal (meaning we don't show files like
App.tsxto showcase config changes)
|
|
||
| ## 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: |
There was a problem hiding this comment.
By adding .md, it will be easier to migrate the files later from .md to .mdx.
| 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: | |
| Pass an [IonicConfig](/docs/developing/config.md#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: |
Adds the following:
ionicConfigwhich allows you to pass config options that get merged withmodein the Playground example.Preview