Here's a component:
class Test extends Component {
bdElements() {
return e.div(
{ className: 'test' }, 'hello',
e.button(
{bdOn_click: () => {this.bdDom.root.classList.add('clicked')}},
'click me',
),
);
}
}
When you click the button, the test component gets the additional classname clicked.
However, as soon as you navigate away from the button, the classname reverts to just test. The reason is that when you clicked the button, bdOnFocus grabbed the current classname (test) and then added bd-focused to it. Then when you navigate away, bdOnBlur restores the original classname, test, since it does not know that you added clicked in the meantime.
As far as I can tell, the workaround is to use the backdraft methods addClassName and removeClassName for manipulating classnames. However...
- that's not always handy, and
- one of the best things about backdraft (as compared to something like reactjs) is that you are allowed to manipulate the DOM directly, with javascript, as opposed to working exclusively through framework methods.
Unfortunately, these classname functions create a tiny bit of the dreaded "shadow DOM," which creates the possibility of conflicts.
I'm wondering if addClassName/removeClassName could work simply by using classList.add() and remove rather than saving and then restoring the "original" classname.
Here's a component:
When you click the button, the
testcomponent gets the additional classnameclicked.However, as soon as you navigate away from the button, the classname reverts to just
test. The reason is that when you clicked the button,bdOnFocusgrabbed the current classname (test) and then addedbd-focusedto it. Then when you navigate away,bdOnBlurrestores the original classname,test, since it does not know that you addedclickedin the meantime.As far as I can tell, the workaround is to use the backdraft methods
addClassNameandremoveClassNamefor manipulating classnames. However...Unfortunately, these classname functions create a tiny bit of the dreaded "shadow DOM," which creates the possibility of conflicts.
I'm wondering if
addClassName/removeClassNamecould work simply by usingclassList.add()andremoverather than saving and then restoring the "original" classname.