Skip to content
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

Feature Request: Auto close all folders #57

Closed
Pickleheaded opened this issue May 25, 2022 · 7 comments
Closed

Feature Request: Auto close all folders #57

Pickleheaded opened this issue May 25, 2022 · 7 comments
Labels
enhancement New feature or request

Comments

@Pickleheaded
Copy link

Would it be possible to add a function so that when you click on a folder all other folders in the Gui close automatically?

Just an idea for larger GUi's.

@georgealways
Copy link
Owner

I'm not sure this is common enough to be part of the core library. For now you could override GUI.prototype.open() to close "sibling" folders. I could see the folders broadcasting open and close events at some point in the future, if there's enough need.

@Pickleheaded
Copy link
Author

Thanks for the reply and I will look at the GUI.prototype.open

@georgealways georgealways added the enhancement New feature or request label May 28, 2022
@branaway
Copy link

branaway commented Jan 2, 2023

Following the prototype idea, however, I could not get it to work. My code is like:

GUI.prototype.open = function ( open = true ) {
this._closed = !open;
this.$title.setAttribute( 'aria-expanded', !this._closed );
this.domElement.classList.toggle( 'closed', this._closed );
if ( open )
this.parent.children
.filter( f => f != this )
.forEach( f=> f.close() );
return this;
};

Any ideas?

@georgealways
Copy link
Owner

Yes, that's bad advice I'm giving above. Most likely this isn't working because we're actually calling the openAnimated method when you open a folder via click. open is for programmatic use.

For now, you could try putting your logic in the setter function of the example here: #67 (comment) — that's a way of observing any change to _closed regardless of what method triggered it.

There will be a better mechanism for listening to folder open and close events in an upcoming release.

@branaway
Copy link

branaway commented Jan 3, 2023

Thanks for the replay, but I did not immediately see how I can use the sample code to achieve the effect, as illustrated here: http://cbfranca.github.io/vertical-responsive-menu/demos/demo.html#

@georgealways
Copy link
Owner

Hi there, I just published version 0.18 which has a new method called gui.onOpenClose. You can use that to listen for folder open/close events and then close sibling folders in the callback.

@Pickleheaded
Copy link
Author

That's perfect, thank you !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants