inveniosoftware / flask-menu

Flask-Menu is a Flask extension that adds support for generating menus.
https://flask-menu.readthedocs.io
Other
53 stars 45 forks source link

active_item return the first item, not the actual active item #46

Closed jrunestone closed 8 years ago

jrunestone commented 8 years ago

Hi,

current_menu.active_item seems to always return the first active menu item and not the actual active item for the page that you are on.

I.e. if I'm in admin / users / edit and I print current_menu.active_item it returns the "admin" item, not the "edit" item.

jirikuncar commented 8 years ago

@swemaniac can you please provide a test case? Thanks

jrunestone commented 8 years ago

Hi!

Here's a demonstration. I should also mention I'm using flask-classy.

https://gist.github.com/swemaniac/aaa9b6a98237fab4fdb3

jirikuncar commented 8 years ago

@swemaniac I was going through your example and its behavior is according to the implementation and thoughts behind default _active_when method (https://github.com/inveniosoftware/flask-menu/blob/master/flask_menu/__init__.py#L88-L94). You can provide your own implementation of active_when function if you want to rely only on comparison with request.endpoint.

There might be a possibility of changing the implementation of active_item property. If you think we should recursively check the children first in active_item, please give us more details about your use-case which would benefit from such a change and it's not easily achievable with custom active_when function.

I'm closing this issue as it is not a bug and we are not planning to change it unless clear use-case is provided.