Articles in this section
Category / Section

How to place editable element in the menu items on Syncfusion Angular Menu Bar Component?

2 mins read

Introduction

Enhancing user experience is crucial in web applications. One way to achieve this is by incorporating interactive components like editable elements within menu items. Angular Menu Bar component provides a flexible way to add these elements, allowing users to interact directly with menu items. This article will guide you through the process of placing editable elements within the Syncfusion Menu Bar component.

Step 1: Create the Menu Bar

To create a basic Menu Bar, you need to initialize the Menu component and define the items you want to display.

Step 2: Add an Editable Element

To add an editable element, such as a text input box, you can use the template property of the Menu Bar. However, there may be an issue where clicking on an input field causes it to lose focus immediately. This behavior can disrupt the user experience by preventing text entry into the input fields within the menu. To address this, you need to assign the e-edit-template class to the input element. This class ensures that the input field retains focus when clicked, allowing for uninterrupted text entry.

Here is an example code snippet that demonstrates how to apply the e-edit-template class to an input element:

<input class="e-edit-template" type="text"/>

Additionally, you need to handle the beforeClose event of the Menu Bar component to prevent the menu from closing when interacting with the input field. The following code snippet shows how to implement the beforeClose event handler:

<ejs-menu [items]='dataSource' (beforeClose)="beforeClose($event)" [fields]='menuFields' [animationSettings]="animation" cssClass="e-template-menu">
    <ng-template #template let-dataSource="">
                {{dataSource.category}}
                <div *ngIf="dataSource.value" style="width:100%;display:flex;justify-content:space-between;">
                    <input class="e-edit-template" type="text"/>
                    <span style="width:100%;">{{dataSource.value}}</span>
                </div>
    </ng-template>
</ejs-menu>

...

public beforeClose(args: BeforeOpenCloseMenuEventArgs): void {
    if (args.event.target && (args.event.target as any).classList.contains("e-edit-template")) {
        args.cancel = true;
    }
}

By adding the e-edit-template class and properly handling the beforeClose event, the input field will maintain focus, and the menu will not close unexpectedly when the input field is clicked.

Example

To see a working example of this solution, please visit the following StackBlitz sample link:

Syncfusion Menu Bar Input Field

Additional References

For more information on Syncfusion’s Menu Bar component and its features, please refer to the official documentation:

By following the guidelines provided in this article, developers can ensure a smooth and user-friendly interaction with input fields within the Syncfusion Menu Bar component.


Conclusion

I hope you enjoyed learning about how to place editable element in the menu items on Syncfusion Angular Menu Bar Component.

You can refer to our Angular Menu feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our Angular Menu example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied