programmatically changing selection of core-menu/core-submenu

102 views
Skip to first unread message

aleem....@gmail.com

unread,
Feb 4, 2015, 10:21:00 PM2/4/15
to polym...@googlegroups.com
I have an application that uses a typical pattern of core-items inside of core-submenus inside of a core-menu. This menu is in a drawer. My main content area is a very long text content based page. Clicking on any of the core-items, jumps you to a specific anchor in the main content. 

My question is how can I programmatically control which core-item/core-submenus are selected? I'd like to implement the pattern where a user scrolls the main content area to a different section and the core-menu selection changes in unison based on what text content is currently visible. I can monitor scroll events in my main window, but how would I change which item is selected in the core-menu?

Rob Dodson

unread,
Feb 18, 2015, 12:23:14 PM2/18/15
to aleem....@gmail.com, polymer-dev
I would give each core-item a unique attribute, maybe data-target="#foo" and give the core-menu a valueattr="data-target" attribute. Then give each of your sections a matching id (ex: <h4 id="foo">). So as you scroll, tell the core-menu to set it's selected property to whatever the current header id is. That should then apply the .core-selected class to the menu item with a matching data-target.

On Wed, Feb 4, 2015 at 7:20 PM, <aleem....@gmail.com> wrote:
I have an application that uses a typical pattern of core-items inside of core-submenus inside of a core-menu. This menu is in a drawer. My main content area is a very long text content based page. Clicking on any of the core-items, jumps you to a specific anchor in the main content. 

My question is how can I programmatically control which core-item/core-submenus are selected? I'd like to implement the pattern where a user scrolls the main content area to a different section and the core-menu selection changes in unison based on what text content is currently visible. I can monitor scroll events in my main window, but how would I change which item is selected in the core-menu?

Follow Polymer on Google+: plus.google.com/107187849809354688692
---
You received this message because you are subscribed to the Google Groups "Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to polymer-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/d1e7f133-b8d3-4341-b88b-e5a3734299c3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Aleem Mawani

unread,
Feb 18, 2015, 12:46:22 PM2/18/15
to Rob Dodson, polymer-dev
This works well for a flat list. How would you adapt this for multiple levels of nestings of submenus. The way I ended up getting it to work was to walk the menu tree myself manually setting the selected property at each level of nesting. I couldn't find a built in way to tell the core-menu to select something at an arbitrary depth.

Rob Dodson

unread,
Feb 18, 2015, 10:18:05 PM2/18/15
to Aleem Mawani, Yvonne Yip, polymer-dev
Hm good question. I don't think it's built in but +yky may know more. 

Rob Dodson

unread,
Feb 18, 2015, 10:22:54 PM2/18/15
to Aleem Mawani, Yvonne Yip, polymer-dev
+ykyyip instead :)
Reply all
Reply to author
Forward
0 new messages