Positioning the dropdown under the search input in Ngbootstrap

Currently, I am referencing this specific documentation as I am interested in constructing a search bar similar to Gmail's layout. The search bar will consist of an input field along with a dropdown button that will display filter options.

Regrettably, the examples provided in the documentation do not address the desired scenario of combining the input field with a dropdown button.

To begin the process, I implemented the following code:

<!-- Search bar-->
<div class="input-group mb-3">
  <input type="text" class="form-control">
  <div class="input-group-append" ngbDropdown role="group" aria-label="Button group with nested dropdown">
    <button class="btn btn-outline-success" ngbDropdownToggle></button>
    <div class="dropdown-menu" ngbDropdownMenu>
      <button class="dropdown-item">One</button>
      <button class="dropdown-item">Two</button>
    </div>
  </div>
</div>

Although everything appears to be in order, there is an issue with the dropdown functionality. It seems to be appearing beneath the button instead of expanding to match the width of the input field. My intuition tells me that this can be rectified with the implementation of a suitable CSS rule.

Answer №1

According to the details provided in the guidelines regarding Manual Triggers, you have the option to link the dropdown menu to the input group and activate the open/close functionality with a button click event.

<!-- Custom search bar-->
<div class="container">
  <div class="input-group mb-3" #myDrop="ngbDropdown" ngbDropdown>
    <input type="text" class="form-control" >
    <div class="input-group-append" role="group" >
    <button (click)="$event.stopPropagation(); myDrop.open();" class="btn btn-outline-success" >Hi</button>
  </div>
  <div class="dropdown-menu" ngbDropdownMenu>
     <button class="dropdown-item">One</button>
    <button class="dropdown-item">Two</button>
  </div>
 </div>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Backgrounds filled by nested <li> elements inside another <li> element

My website features a sidebar menu with nested lists. When hovering over a list item, a sub-list appears. However, I am having an issue where the background color fills the entire sub-list instead of just the first list item. See the images below for clari ...

The close button is not functioning properly

I created a script to close my div element by clicking on the 'x' icon, but instead of deleting the div only, the whole page gets deleted. I'm not sure where I went wrong, can anyone help me? HTML <div class="note"> <span id ...

Challenges faced when incorporating ng-content within Angular components

I am facing a specific issue where I need to pass code from a file containing a component to its child component. My initial approach was to use ng-content, but unfortunately, this method did not work as expected. I am unsure if the ng-content usage is inc ...

A reliable approach for dynamically altering SVG graphics

It seems like IE10 does not support CSS transformations for SVGs, only attribute transformations. Here is an example: <svg><rect id="myrect" width="200" height="200"></rect></svg> setTimeout(function() { var r = document.getE ...

Surprising sight of a blank canvas behind the font-awesome icon

Is there a way to remove the unexpected white background that appears when adding a font-awesome icon? Here is the HTML code: <div class="notifications-window" id="close-notifications"> <div class="notifications-header&qu ...

Using class binding for both ternary and non-ternary attributes

Suppose we have a tag that utilizes a ternary operator to apply alignment: <td :class="alignment ? ('u-' + alignment) : null" > This functions as intended since the pre-defined alignment classes are in place, now if we want to ...

An issue occurred while loading: Uncaught ReferenceError: module is missing from the http://localhost:9876/_karma_webpack_/scripts.js file on line 1

Error image I encountered an error while performing jasmine karma unit testing with angular. Can anyone provide assistance on this issue? Here is my karma.conf.js file: // Karma configuration file, see link for more information //<br> https://karma ...

2 entities - perform an action once both have successfully provided data

Upon calling this.pokojeService.pobierzPokoje() and this.pokojeService.pobierzTypyPokoi(), I subscribe to their respective observables. Once the data is retrieved, it is stored in this.pokoje and this.pokojeTypy variables. These two observables are crucia ...

Using Angular: How to set the index value from a dropdown to a local variable after a button is clicked

Can someone please provide guidance on how to assign the index value (i = index) to EmployeeIndex: any; after a button click event? Your suggestions are greatly appreciated. Here is my code: HTML <select class="form-control" [(ngModel)]="EmployeeNam ...

What is the best way to update the video source upon clicking a link with JQuery?

Is there a way to change the video src using jQuery when a link is clicked? For example, if the user clicks on "#staff", the video src will be updated. <ul class="nav nav-pills" > <li role="presentation" class="loginPills"><a ...

Angular-6 Issue: Default Value Not Displaying in Drop-Down List

I am attempting to bind an array into a list. The binding part is functioning correctly, but the default value of the drop down is not displaying. Initially, the array does not contain any values. Here is the code snippet: <select (change)="select($ev ...

"Woops! An error occurred with the message: "SassError: Could not locate the specified target selector" while working with SCSS Modules and incorporating

Currently, I am working with Next.js and utilizing SCSS Modules. To incorporate Bootstrap into my project, I opted to install it using the command npm install bootstrap. Following this installation, I went ahead and created a new file titled common.scss wi ...

Incorporating Google Pay functionality within Angular applications

I have been attempting to incorporate Google Pay into my Angular project, but I am struggling to find reliable resources. My main issue revolves around the following code... <script async src="https://pay.google.com/gp/p/js/pay.js" onloa ...

What measures can I take in Angular to ensure that only one user is logged

Our project utilizes a backend .NET Core API and a frontend built with Angular. When sending an API request, user information is stored in local storage. How can we ensure that the same user does not log in simultaneously from different browsers or clien ...

Twitter Bootstrap navbar-collapse can be seen overlapping navbar-header section, causing a

I seem to be having a problem with the Twitter Bootstrap navbar-collapse element overlapping the navbar-header logo, 'the alpha', and causing the link to be unclickable. As shown in the image below, the alpha logo has an href link but is not cli ...

What is the best way to horizontally align divs with CSS?

I have been using a combination of table and CSS to center divs on my page. Here is the code I'm currently using: <table width="69" border="0" align="center"> <tr> <td width="59"> <div style="position:relative;"> ...

Leveraging Angular's capability to import files directly from the assets

I recently installed a library via npm and made some modifications to one of the modules. python.js If I delete the node_modules folder and run npm install, I am concerned that I will lose my changes. Is there a way to preserve these modifications by mov ...

Creating a semi-circular shaped rectangle using CSS

Is it possible to achieve the unique rectangle borders shown in the image using border-radius or any other CSS property? Here's what I'm trying to create: https://i.sstatic.net/YKPEW.png Currently, this is what I've been able to achieve us ...

Comparing Twitter Bootstrap and PrimeNg: The Ultimate Guide for UI Development in Angular 2

After using twitter bootstrap for a while, I transitioned to Angular 2 and began exploring different CSS libraries. I discovered options like ngSemantic, Angular2 Material, ng-bootstrap, and ng2-bootstrap, but primeNg caught my eye with its wide range of c ...

Prevent the Focus on Submit Button in CSS

Whenever a text field is focused in Opera, the submit button ends up with an unsightly black border. A screenshot clearly shows this issue. At the bottom of the image, you can see how the textarea is focused and the submit button looks unappealing. Is th ...