Skip to content

Commit ebd0827

Browse files
dimodintacheva
andauthored
docs(panelbar): OnExpand and OnCollapse events (#1095)
* docs(panelbar): OnExpand and OnCollapse events * Update components/panelbar/events.md Co-authored-by: Nadezhda Tacheva <[email protected]>
1 parent a0ffc26 commit ebd0827

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

components/panelbar/events.md

+99
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ This article explains the events available in the Telerik TreeView for Blazor:
1515
* [OnItemClick](#onitemclick)
1616
* [ExpandedItemsChanged](#expandeditemschanged)
1717
* [OnItemRender](#onitemrender)
18+
* [OnExpand and OnCollapse](#onexpand-and-oncollapse)
1819

1920
## OnItemClick
2021

@@ -304,6 +305,104 @@ If the item that is customized has children, they will also inherit the styles a
304305
}
305306
````
306307

308+
## OnExpand and OnCollapse
309+
310+
The `OnExpand` and `OnCollapse` events fire when the user tries to expand/collapse an item, but *before* the actual action takes place.
311+
312+
The `OnExpand` handler receives an argument of type `PanelBarExpandEventArgs`.
313+
314+
The `OnCollapse` handler receives an argument of type `PanelBarCollapseEventArgs`.
315+
316+
Both event arguments expose an `Item` and `IsCancelled` properties. To cancel each event, set `args.IsCancelled` to `true`. In this case, the item will gain focus and selection, but its state will remain unchanged.
317+
318+
>caption PanelBar OnExpand and OnCollapse Events
319+
320+
````CSHTML
321+
<TelerikPanelBar Data="@PanelBarItems"
322+
OnExpand="@OnPanelBarExpand"
323+
OnCollapse="@OnPanelBarCollapse">
324+
</TelerikPanelBar>
325+
326+
@code {
327+
private List<PanelBarItem> PanelBarItems { get; set; }
328+
329+
private async Task OnPanelBarExpand(PanelBarExpandEventArgs args)
330+
{
331+
Console.WriteLine($"The expanded item is: {(args.Item as PanelBarItem).Text}");
332+
333+
// to prevent the event
334+
//args.IsCancelled = true;
335+
}
336+
337+
private async Task OnPanelBarCollapse(PanelBarCollapseEventArgs args)
338+
{
339+
Console.WriteLine($"The collapsed item is: {(args.Item as PanelBarItem).Text}");
340+
}
341+
342+
protected override void OnInitialized()
343+
{
344+
PanelBarItems = LoadFlatData();
345+
346+
base.OnInitialized();
347+
}
348+
349+
private List<PanelBarItem> LoadFlatData()
350+
{
351+
List<PanelBarItem> items = new List<PanelBarItem>();
352+
353+
items.Add(new PanelBarItem()
354+
{
355+
Id = 1,
356+
Text = "Company",
357+
ParentId = null,
358+
HasChildren = false,
359+
});
360+
361+
items.Add(new PanelBarItem()
362+
{
363+
Id = 2,
364+
Text = "Contact us",
365+
ParentId = null,
366+
HasChildren = true,
367+
});
368+
369+
items.Add(new PanelBarItem()
370+
{
371+
Id = 3,
372+
Text = "Email",
373+
ParentId = 2,
374+
HasChildren = false
375+
});
376+
377+
items.Add(new PanelBarItem()
378+
{
379+
Id = 4,
380+
Text = "LinkedIn",
381+
ParentId = 2,
382+
HasChildren = false
383+
});
384+
385+
items.Add(new PanelBarItem()
386+
{
387+
Id = 5,
388+
Text = "Audio",
389+
ParentId = null,
390+
HasChildren = false
391+
});
392+
393+
return items;
394+
}
395+
396+
public class PanelBarItem
397+
{
398+
public int Id { get; set; }
399+
public string Text { get; set; }
400+
public int? ParentId { get; set; }
401+
public bool HasChildren { get; set; }
402+
}
403+
}
404+
````
405+
307406
## See Also
308407

309408
* [PanelBar Overview]({%slug panelbar-overview%})

0 commit comments

Comments
 (0)