Modal updates 2 (#901)

* Fix incorrect visible value

* Focus element when visibility is set

* Add isVisible function
This commit is contained in:
toasted-nutbread 2020-10-08 22:44:55 -04:00 committed by GitHub
parent bedcad6ab2
commit 1ae8fb4bfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -29,11 +29,23 @@ class Modal extends EventDispatcher {
return this._node; return this._node;
} }
isVisible() {
if (this._useJqueryModal()) {
return !!(this._getWrappedNode().data('bs.modal') || {}).isShown;
} else {
return this._node.classList.contains(this._visibleClassName);
}
}
setVisible(value) { setVisible(value) {
value = !!value;
if (this._useJqueryModal()) { if (this._useJqueryModal()) {
this._getWrappedNode().modal(value ? 'show' : 'hide'); this._getWrappedNode().modal(value ? 'show' : 'hide');
} else { } else {
this._node.classList.toggle(this._visibleClassName, value); const {classList} = this._node;
if (classList.contains(this._visibleClassName) === value) { return; }
classList.toggle(this._visibleClassName, value);
if (value) { this._node.focus(); }
} }
} }
@ -86,7 +98,7 @@ class Modal extends EventDispatcher {
const visible = this._node.classList.contains(this._visibleClassName); const visible = this._node.classList.contains(this._visibleClassName);
if (this._visible === visible) { return; } if (this._visible === visible) { return; }
this._visible = visible; this._visible = visible;
this.trigger('visibilityChanged', {visible: false}); this.trigger('visibilityChanged', {visible});
} }
_useJqueryModal() { _useJqueryModal() {