This is a migrated thread and some comments may be shown as answers.

Best way to check if an item is expanded

2 Answers 804 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 23 Jul 2013, 06:34 PM
Hi,

I was wondering what is considered the "best" way to determine if a PanelBarItem is expanded or not? So far what I've been able to come up with is to check the "aria-expanded" property or see if the child <ul> is visible, both of which feel a bit dirty. Is there a better way, or is one of these two methods considered "better" than the other?

For context, I'm retrieving the item to check by using jquery.closest from one of the child items. Example:
function (id) {
  var child = $("#s-list-objectChild-" + id);
  var parent = child.closest("[id^='s-list-object-']");
  if (parent.isExpanded()) // Perform check here
    doSomething();
  else
    doSomethingElse();
}
Thanks,
Jeff

2 Answers, 1 is accepted

Sort by
0
Accepted
Kamen Bundev
Telerik team
answered on 26 Jul 2013, 07:48 AM
Hi Jeff,

There's currently no integrated easy way to do that. I think it will be easiest for you to use the CSS class .k-state-active to determine if the item is expanded. Check this jsBin for a quick example.

Regards,
Kamen Bundev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Jeff
Top achievements
Rank 1
answered on 26 Jul 2013, 03:20 PM
Yeah, I figured there was no real easy way, but thanks for your input.

Edit: Actually, I have to use the "aria-expanded" attribute in my code. Since my PanelBar's expand mode is set to "single," the first item is already expanded on load. This causes the "k-state-active" class to be applied, even though the action associated with expanding that item may not have been fired yet. Luckily (and somewhat incorrectly), the "aria-expanded" attribute does not change to true if the item starts out expanded.
Tags
PanelBar
Asked by
Jeff
Top achievements
Rank 1
Answers by
Kamen Bundev
Telerik team
Jeff
Top achievements
Rank 1
Share this question
or