|
| 1 | +--- |
| 2 | +sidebar_label: toggle-list |
| 3 | +title: toggle-list Event |
| 4 | +description: You can learn about the toggle-list event in the documentation of the DHTMLX JavaScript RichText library. Browse developer guides and API reference, try out code examples and live demos, and download a free 30-day evaluation version of DHTMLX RichText. |
| 5 | +--- |
| 6 | + |
| 7 | +# toggle-list |
| 8 | + |
| 9 | +### Description |
| 10 | + |
| 11 | +@short: Fires when the user toggles a list on the selected blocks |
| 12 | + |
| 13 | +The `toggle-list` event powers the context-aware bulleted/numbered list buttons. Instead of inserting a new list, the event inspects the current selection and picks one of four behaviors automatically: |
| 14 | + |
| 15 | +| Mode | When it fires | Result | |
| 16 | +| ----------- | --------------------------------------------------------------- | ------------------------------------------------------------------- | |
| 17 | +| **Wrap** | The selection covers only paragraphs | Each paragraph becomes a list item inside one new list container | |
| 18 | +| **Unwrap** | Every covered item is in a list of the clicked type | The items revert to paragraphs; the list container is removed | |
| 19 | +| **Convert** | Every covered item is in a list, but at least one of the lists is of the other type | The list flips its type (bulleted ↔ numbered) in place | |
| 20 | +| **Mixed** | The selection mixes paragraphs and list items | Paragraphs become items and everything joins one list of the type | |
| 21 | + |
| 22 | +### Usage |
| 23 | + |
| 24 | +~~~jsx {} |
| 25 | +"toggle-list": ({ type: TListType }) => boolean | void; |
| 26 | + |
| 27 | +type TListType = "bulleted" | "numbered"; |
| 28 | +~~~ |
| 29 | + |
| 30 | +### Parameters |
| 31 | + |
| 32 | +The callback of the `toggle-list` event can take an object with the following parameter: |
| 33 | + |
| 34 | +- `type` - the type of the list to toggle. You can specify the following values: |
| 35 | + - `"bulleted"` - bulleted (unordered) list |
| 36 | + - `"numbered"` - numbered (ordered) list |
| 37 | + |
| 38 | +:::info |
| 39 | +To handle inner events, use [**Event Bus methods**](api/overview/event_bus_methods_overview.md) |
| 40 | +::: |
| 41 | + |
| 42 | +### Example |
| 43 | + |
| 44 | +~~~jsx {5-9} |
| 45 | +// initialize RichText |
| 46 | +const editor = new richtext.Richtext("#root", { |
| 47 | + // configuration properties |
| 48 | +}); |
| 49 | +// subscribe to the "toggle-list" event |
| 50 | +editor.api.on("toggle-list", (obj) => { |
| 51 | + console.log(obj.type); |
| 52 | + console.log("The list was toggled"); |
| 53 | +}); |
| 54 | +~~~ |
| 55 | + |
| 56 | +**Change log:** The event was added in v2.0.6 |
0 commit comments