2021-04-21 17:03:33 +08:00
|
|
|
# toggleList
|
2022-06-08 18:41:14 +08:00
|
|
|
`toggleList` will toggle between different types of lists.
|
2021-04-21 17:03:33 +08:00
|
|
|
|
2022-06-08 18:41:14 +08:00
|
|
|
## Parameters
|
|
|
|
`listTypeOrName: string | NodeType`
|
|
|
|
|
|
|
|
The type of node that should be used for the wrapping list
|
|
|
|
|
|
|
|
`itemTypeOrName: string | NodeType`
|
|
|
|
|
|
|
|
The type of node that should be used for the list items
|
|
|
|
|
Adds attributes to toggleList (#3776)
* Adds attributes to toggleList
When dealing with different variants of bullet lists, I wanted to adopt the same technique I used for different paragraph variants. Since `wrapInList` is capable of receiving attributes, just like `setNode` is, I don't see any reason why `toggleList` should not be capable of the same.
Here's my bullet list extension in action that is in need of attributes support.
```js
export const CustomBulletList = BulletList.extend({
content: 'listItem*',
addAttributes() {
return {
variant: {
default: DEFAULT_LIST,
renderHTML: attributes => {
return {
class: `list-${attributes.variant}`,
};
},
},
};
},
addCommands() {
return {
toggleBulletList: attributes => (c) => {
return c.commands.toggleListCustom(this.name, this.options.itemTypeName, attributes);
},
};
},
});
```
* Update toggle-list.md
* Update toggle-list.md
2023-03-03 16:59:45 +08:00
|
|
|
`keepMarks?: boolean`
|
|
|
|
|
|
|
|
If marks should be kept as list items or not
|
|
|
|
|
|
|
|
`attributes?: Record<string, any>`
|
|
|
|
|
|
|
|
The attributes that should be applied to the list. **This is optional.**
|
|
|
|
|
2022-06-08 18:41:14 +08:00
|
|
|
## Usage
|
|
|
|
```js
|
|
|
|
// toggle a bullet list with list items
|
|
|
|
editor.commands.toggleList('bullet_list', 'list_item')
|
|
|
|
|
|
|
|
// toggle a numbered list with list items
|
|
|
|
editor.commands.toggleList('ordered_list', 'list_item')
|
|
|
|
```
|