Update the overflow property to overflow-auto instead of overflow-visible when the element exceeds the size of the viewport

I am facing an issue with my Angular component that opens another component as an offcanvas:

  openTop() {
    this.offcanvasService.open(AdvancedSearchComponent, {
      position: 'top',
      backdropClass: 'bg-dark',
      panelClass: 'h-25 bg-danger text-bg-danger flex-column',
      keyboard: true,
    });
  }

In the offcanvas component, I have the following structure:

<nav class="navbar navbar-expand-lg navbar-dark bg-danger">
  <div class="navbar-toggler border-0 ps-2 ps-sm-3 py-2 py-lg-0">
    <a class="navbar-brand" href="#"
      ><img src="assets/..."
    /></a>
  </div>
  <button
    class="navbar-toggler mx-2 mb-2"
    type="button"
    data-bs-toggle="collapse"
    data-bs-target="#navbarSearch"
    aria-controls="navbarSearch"
    aria-expanded="false"
    aria-label="Toggle navigation"
  >
    <span class="navbar-toggler-icon"></span>
  </button>
  <div class="collapse navbar-collapse flex-grow-1" id="navbarSearch">
    <form
      class="overflow-auto flex-grow-1"
      (ngSubmit)="searchTask()"
      [formGroup]="searchForm"
    >
      <div class="offcanvas-header pe-0 pt-0 pb-1 align-items-start">
...

The relevant CSS for this issue is as follows:

:host {
  height: 100%;
  display: flex;
  flex-direction: column;
}
form {
  scrollbar-gutter: stable;
}

When I add overflow-auto to the <nav> element in the top offcanvas, its height becomes 25vh and a scroll bar appears when the content exceeds the vertical space.

However, if I add overflow-visible or no overflow class at all to the top <nav> element, the offcanvas panel expands beyond the screen when the content doesn't fit vertically. This causes issues when buttons within the panel trigger content growth without a scrollbar, due to the use of overflow-visible. My goal is to have overflow-visible when the offcanvas panel occupies 25%-100% of the viewport, but switch to overflow-auto when the content exceeds 100% of the viewport.

The desired outcome is for the top offcanvas panel to dynamically adjust to the content size, while enabling a scrollbar to view overflow when the content surpasses the screen boundaries.

Attempts made so far:

  • Some Stack Overflow suggestions point out that setting body {overflow: hidden} might be causing the issue. Although removing this style from the body added a scrollbar, it only applies to the background content rather than the offcanvas content.

  • Experimented with additional <div> elements using different classes.

  • Tried utilizing max-height and height properties in CSS, as well as applying corresponding Bootstrap classes to the <nav> element, but didn't achieve the desired result.

  • Some solutions suggest implementing padding, but I couldn't comprehend how to apply it effectively in this context.

Answer №1

I managed to figure out the solution I was looking for. It seemed that using .h-auto was causing the offcanvas panel to have a fixed height of 100vh, regardless of whether the collapsible elements were expanded or not. The key was to switch to using .overflow-visible when opening the offcanvas panel, which allowed the height of the panel to adjust based on the content.

  openTop() {
    this.offcanvasService.open(AdvancedSearchComponent, {
      position: 'top',
      backdropClass: 'bg-dark',
      panelClass: 'h-25 bg-danger text-bg-danger d-flex flex-column overflow-visible',

      keyboard: true,
    });
  }

Then, to add a scrollbar, I realized that I needed to set a specific height for the child element:

    <form
      class="overflow-auto flex-grow-1 form-height"
      (ngSubmit)="searchTask()"
      [formGroup]="searchForm"
    >

css:

.form-height {
  max-height: 95vh;
}

This approach worked perfectly: the offcanvas now has a minimum height of 25vh, expands up to about 100vh, and adds a scrollbar if the content exceeds the viewport size. Using .overflow-auto.h-auto wasn't able to dynamically adjust the height based on the content, resulting in the offcanvas panel filling the entire screen even when all elements were collapsed.

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

Angular 4 encounters performance issues when rendering numerous base64 images simultaneously

I'm currently working on a private project that involves using Angular 4 (specifically version 4.1.2). One issue we're facing is related to rendering multiple base64 images on an HTML page. The performance of the application significantly drops w ...

Enhance the Search Box with a Vibrant Glow Effect When in Use

I need help adding a glow effect color around a search field when a user clicks on it to type. I want the border to have a shadow and the glow effect to be orange. I have included the CSS below, but I'm unsure of what to change or add. Any assistance ...

css - Showcasing images with a horizontal scrollbar

I'm having an issue with displaying multiple images in a fixed-width div horizontally. I want to have a horizontal scroll bar for the images that exceed the width of the div. Currently, the images are appearing vertically instead of side-by-side. Is ...

Update Bootstrap Vue to change the colors of the breadcrumbs

Struggling to customize the look of bootstrap-vue breadcrumbs? I've attempted various combinations of classes and styles in the breadcrumb and breadcrumb-item tags, but to no avail. Every time, I end up with blue or grey text on a light grey backgroun ...

Angular is patiently awaiting the completion of the subscription

Currently, I am in the process of developing a test application using Angular. The challenge arises when I attempt to retrieve data through a Get request and then return a value based on that data. The code snippet below outlines the scenario: public getN ...

The accuracy of VW and VH units is questionable

width: 100vw;/* Taking up the entire viewport width */ height: 100vh;/* Occupying the full height of the viewport*/ Despite my efforts to make this CSS match the exact dimensions of the viewport at 100%, it seems to be too large and causing overflow on th ...

.observe({ action: (response) => { this.updateData = response.Items; }. what comes after this

I need some guidance on what comes next within the callback function .subscribe({ next: (data) => { this.newData = data.Items; } ...

What is the method for reaching a service in a different feature module?

Currently, I am utilizing Angular 2/4 and have organized my code into feature modules. For instance, I have a Building Module and a Client Module. https://i.stack.imgur.com/LvmkU.png The same structure applies to my Client Feature Module as well. Now, i ...

What causes the button size to change in Bootstrap when switching to a spinner?

Every time I switch from a spinner back to a button, the button's size changes. I am struggling to identify the cause of this issue. function resizeButton() { var btn = document.getElementById('submitBtn'); btn.innerHTML = ' ...

Height adjustment for flexbox children

Can someone assist me with marking up a todo list? I am attempting to set the height of div.main-tasks equal to div.tasks so that the former fills the entire latter. Unfortunately, I am unsure how to achieve this. You can refer to the following image for c ...

The production build of Angular 2 with special effects amplification

I am currently working on an Angular 2 Beta 8 app that I need to bundle and minify for production deployment. Despite configuring the system to generate a Single File eXecutable (SFX) bundle, I am encountering issues with creating a minified version of the ...

Eliminate the Border from Bootstrap 5 navigation-toggler through standard css styling

I am trying to eliminate the light grey border around the mobile 'hamburger' menu. I am utilizing font-awesome and Bootstrap 5 (imported through CDN) to create it, but I can't figure out how to get rid of the rounded border. html <na ...

The specified file 'node_modules/bingmaps/types/MicrosoftMaps/Microsoft.Maps.d.ts' cannot be treated as a module

Currently utilizing the official npm package for bingmaps with angular 7 (cli). I have followed the configuration instructions outlined in the npm documentation, and I am successfully loading the basic bing map. In my component.ts file, I included the ...

Creating a sleek appearance for Bootstrap input within the selectize.js component by mimicking the input-sm

I am currently working with a selectize component that appears like this: https://i.sstatic.net/z2aTw.png My objective is to adjust the appearance of the search input to make it smaller by changing its class from the standard bootstrap input to input-sm. ...

Tips for converting mat-paginator in Angular 4?

Can you provide any suggestions on how to translate the phrase "Items per page" within the Angular mat-paginator tag, which is a component of Material Design? ...

Is there any Ahead-Of-Time (AOT) compiler available for ReactJs similar to the one used in Angular

Angular 4.0 has an Ahead-Of-Time compiler available, as mentioned in their documentation. Is there a corresponding compiler for ReactJS, or is ReactJS designed to not require one? ...

The element fa-icon is unrecognized within the Reusable Module

Can anyone help me understand why I am encountering this issue with a reusable Module (or what mistake I have made)? ERROR Error: Uncaught (in promise): Error: Template parse errors: 'fa-icon' is not a known element Just to clarify: fa-icon ...

Updates made to the Transform property in Mui Theme are not appearing in the browser

I'm looking to modify the MuiInputLabel.outlined. While I can see various changes when inspecting in the browser, I'm having trouble seeing the transform property change specifically. This is the current configuration of my MuiInputLabel: MuiInp ...

I'm looking to switch out the `~` to turn it into a URL for the backend, seeing as `<img alt="" src="~/media/Banner/plane.JPG">` is returning a 404 error

1. Received an HTTP Request and JSON response from the backend localhost:3000 (entered value using wysiwyg) { "Description": "&lt;img alt=&quot;&quot; src=&quot;~/media/Banner/plane.JPG&quot; /&gt;1 test berita&lt ...

Instructions for loading static HTML content in the browser from a specific directory

Exploring my file hierarchy: public---| |-index.html |-static-| |-static.html After launching the project at localhost:4000, it directs to the public folder and displays index.html. However, I am looking to load static ...