Search code examples
javascriptjquerycssbootstrap-4bootstrap-popover

Bootstrap 4: Why popover inside scrollable dropdown doesn't show?


I want this to work just like Bootstrap 3. When I have a dropdown with scrollbar on hover popover, and I think there is a problem with Bootstrap 4. I need overflow:hidden; to make the dropdown scroll, but the popover is hidden too. I tried to use container:'body' but it didn't work.

$(document).ready(function() {
  $('[data-toggle="popover"]').popover({
    html: true,
    container: 'body'
  });
});
.dropdown-menu{
	height: 150px;
	overflow: hidden;
	overflow-y: auto
}
<!DOCTYPE html>
<html>
<head>
  <title>Bootstrap Example</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  <h2>Dropdowns</h2>
                                     
  <div class="dropdown">
    <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
      Dropdown button
    </button>
    <div class="dropdown-menu">
      <a class="dropdown-item" href="#"	title="Header" data-toggle="popover" data-placement="right" data-trigger="hover"data-content="Some content">Link 1</a></a>
      <a class="dropdown-item" href="#" title="Header" data-toggle="popover" data-placement="right" data-trigger="hover" data-content="Some content">Link 2</a>
      <a class="dropdown-item" href="#">Link 3</a>
      <a class="dropdown-item" href="#">Link 4</a>
      <a class="dropdown-item" href="#">Link 5</a>
      <a class="dropdown-item" href="#">Link 6</a>
      <a class="dropdown-item" href="#">Link 7</a>
      <a class="dropdown-item" href="#">Link 8</a>
      <a class="dropdown-item" href="#">Link 9</a>
    </div>
  </div>
</div>


Solution

  • There are some issues with popper.js, and how it positions dropdowns, popovers and tooltips. The solution is to set the data-boundary option on the popovers to window...

    Demo on Codeply

    $(document).ready(function() {
      $('[data-toggle="popover"]').popover({
      });
    });
    .dropdown-menu{
    	height: 150px;
    	overflow: hidden;
    	overflow-y: auto
    }
    <!DOCTYPE html>
    <html>
    <head>
      <title>Bootstrap Example</title>
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
    </head>
    <body>
    <div class="container">
      <h2>Dropdowns</h2>
      <div class="dropdown">
        <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
          Dropdown button
        </button>
        <div class="dropdown-menu">
          <a class="dropdown-item" href="#"	title="Header" data-boundary="window" data-toggle="popover" data-placement="right" data-trigger="hover"data-content="Some content">Link 1</a></a>
          <a class="dropdown-item" href="#" title="Header" data-boundary="window" data-toggle="popover" data-placement="right" data-trigger="hover" data-content="Some content">Link 2</a>
          <a class="dropdown-item" href="#">Link 3</a>
          <a class="dropdown-item" href="#">Link 4</a>
          <a class="dropdown-item" href="#">Link 5</a>
          <a class="dropdown-item" href="#">Link 6</a>
          <a class="dropdown-item" href="#">Link 7</a>
          <a class="dropdown-item" href="#">Link 8</a>
          <a class="dropdown-item" href="#">Link 9</a>
        </div>
      </div>
    </div>