-
Notifications
You must be signed in to change notification settings - Fork 36
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
Add button to toolbar #249
Comments
I thought the You can add <template>
<div id="app">
<vue-trix ref="trixRef" v-model="text" @trix-initialize="trixInit" />
</div>
</template>
<script>
import VueTrix from "vue-trix";
import Trix from "trix";
Trix.config.textAttributes.red = {
style: { color: "red" },
parser(element) {
return element.style.color === "red";
},
inheritable: true,
};
export default {
name: "App",
components: {
VueTrix,
},
data() {
return {
text: 'Hello <span style="color: red">red</span>',
};
},
methods: {
trixInit() {
const buttonHTML =
'<button type="button" class="trix-button" data-trix-attribute="red" tabindex="-1">RED</button>';
this.$el
.querySelector(".trix-button-group--text-tools")
.insertAdjacentHTML("beforeend", buttonHTML);
},
},
};
</script>
<style>
#app {
font-family: Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
</style> Codesandbox: https://codesandbox.io/s/immutable-cookies-dljk0?file=/src/App.vue NOTE: if you have hot-reload - make sure you close the tab and re-open is since, trix registers itself as a custom element, and importing it in your code again will try to re-register it. |
@avioli this doesn't seem to work for me. I get the following error: Uncaught DOMException: Failed to execute 'define' on 'CustomElementRegistry': the name "trix-toolbar" has already been used with this registry I exited out of hot-reload like your note states and recompiled and I'm still getting this error. Not sure how to get around it. |
@avioli nevermind, I was able to get it to work. I had to delete the node modules, reinstall, and recompile then it worked for me. |
I need to add a custom function to the toolbar, to change the text color.
Here is exactly what I want to do with the standard Trix editor https://jsfiddle.net/javan/egg7fgvv/. Here's a snippet of that code:
I'm trying to achieve the same thing but with VueTrix rather than Trix and I'm stuck, I just can't see how to get it to work. Does anyone have any ideas?
Thanks for your help :)
The text was updated successfully, but these errors were encountered: