bustle / mobiledoc-kit

A toolkit for building WYSIWYG editors with Mobiledoc
https://bustle.github.io/mobiledoc-kit/demo/
MIT License
1.55k stars 150 forks source link

Add Editor#removeAttribute to remove section attributes 🕯 #706

Closed ZeeJab closed 4 years ago

ZeeJab commented 4 years ago

Adds a symmetrical removeAttribute method to Editor and PostEditor to match the two implementations of setAttribute.

The motivation for this change is to support removing an attribute if a user sets it back to the default value. For example, currently a new section does not have a text-align attribute when created and defaults to being left aligned. However, if the user changes the section to be right aligned, setting the text-align attribute to right, there is currently no way to later change that section back to the default "no explicit text-align" state.

Another option would be to treat setting null or undefined attribute values as removal. However, it seemed better to add an explicit removeAttribute method to align with the DOM attribute API, and there may be use cases where null or undefined attribute values are desired.