From 4caf68688d7830c3586f77c89a21c3c48aa9073a Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Sat, 10 Aug 2019 14:26:16 +0200 Subject: [PATCH] Complete `Updating traits at run-time` section in trait docs --- docs/modules/Traits.md | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/docs/modules/Traits.md b/docs/modules/Traits.md index 259dbf9e5..931706fb1 100644 --- a/docs/modules/Traits.md +++ b/docs/modules/Traits.md @@ -216,9 +216,31 @@ const component = editor.getSelected(); component.getTrait('type').set('options', [ { id: 'opt1', name: 'New option 1'}, { id: 'opt2', name: 'New option 2'}, -]) +]); +// or with multiple values +component.getTrait('type').set({ + label: 'My type', + options: [...], +}); ``` +You can also easily add new traits or remove some other by using [`addTrait`](/api/component.html#addtrait)/[`removeTrait`](/api/component.html#removetrait) + +```js +// Add new trait +const component = editor.getSelected(); +component.addTrait({ + type: 'text', + ... +}, { at: 0 }); +// The `at` option indicates the index where to place the new trait, +// without it, the trait will be appended at the end of the list + +// Remove trait +component.removeTrait('type'); +``` + + ## Define new Trait type