Having trouble getting StencilJS Bottomsheet to work properly? Looking for a way to smoothly slide up your content?

I've been working on creating a Bottomsheet in Stencil, but I'm facing an issue where it shows up suddenly when activated. My goal is to display the overlay when the active property is set, and then smoothly slide up the content. Below is my component code along with its corresponding style:

Component:

import { Component, Prop, State, h, Listen } from '@stencil/core'

@Component({
    tag: 'my-bottomsheet',
    styleUrl: 'my-bottomsheet.scss',
    shadow: true
})

export class myBottomSheet {
    @State() active: boolean = false;

    toggle() {
        this.active = true;
    }

    render() {
        return (
            <div class="my-bottomsheet">
                <button onClick={() => this.toggle()}>Show</button>
                { this.active &&
                    <div class="my-bottomsheet-overlay">
                        <div class="my-bottomsheet-content">
                            <span>This is the content!</span>
                        </div>
                    </div>
                }
            </div>
        )
    }
}

Style:

.my-bottomsheet-overlay {
    height: 100%;
    width: 100%;
    position: fixed; /* Stay in place */
    z-index: 1; /* Sit on top */
    left: 0;
    top: 0;
    background-color: rgba(0, 0, 0, 0.4); /* Black w/opacity */
    overflow-x: hidden; /* Disable horizontal scroll */
}

.my-bottomsheet-content {
    background-color: #fff;
    overflow: hidden;
    position: absolute;
    bottom: 0;
    width: 100%;
    transform: translateY(0);
    transition: transform 0.5s; /* Added missing unit for animation duration */
}

The desired behavior is for the overlay to appear suddenly while the content smoothly slides up. Could you provide guidance on what may be missing or incorrect in my implementation?

Answer №1

Oops, rookie mistake alert! Trying to manipulate the height using "height: auto" won't work here. However, you can use either max-height or a specific value for height instead. Here's how you can correct it:

.my-overlay {
    width: 100%;
    height: 100%;
    position: fixed;
    z-index: 1;
    left: 0;
    top: 0;
    background-color: rgba(0, 0, 0, 0.4);
    overflow-x: hidden;
}

.my-content {
    background-color: #fff;
    overflow: hidden;
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    animation: slideUp 0.5s;
    max-height: 300px; /* Or any desired height */
    z-index: 2;
}

@keyframes slideUp{
    0% {
        max-height: 0;
    }

    100% {
        max-height: 300px;
    }
}

Feel free to use this bottomsheet solution as it is fully functional.

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

Display or conceal a <div> segment based on the drop down selection made

A dropdown menu controls the visibility of certain div elements based on the selection made. While this functionality is working for one dropdown, it's not working for another even though the code is very similar. I've tried various solutions but ...

Guide to selecting multiple rows at once using ng-options in a list

Need assistance with an HTML list: I have a box displaying a list where users can select multiple items to save. The saving and retrieving process is functional as the selectedList stores the user's previous selections, while fullList contains all av ...

The ng-app directive for the Angular project was exclusively located in the vendor.bundle.js.map file

Currently, I am diving into an Angular project that has been assigned to me. To get started, I use the command "gulp serve" and then access the development server through Chrome by clicking on "http://localhost:3000". During my investigation in Visual Stu ...

I possess a JSON object retrieved from Drafter, and my sole interest lies in extracting the schema from it

Working with node to utilize drafter for generating a json schema for an application brings about too much unnecessary output from drafter. The generated json is extensive, but I only require a small portion of it. Here is the full output: { "element": ...

Having trouble accessing the data I'm setting in a separate component using the Context API

Currently working on my own project and I've encountered a problem while using the Context API. It's my first time using it. The issue I'm facing is that I can't seem to console.log the data I'm setting. I'm trying to create ...

Koa.js route() isn't a defined function

Recently, I created a basic koa app that should return rss xml based on a tag using a parameter. However, for some reason the middleware is unable to read the router from the router file and I cannot figure out why it's not working as expected. The ap ...

What is the best way to identify a specific AdWords account while utilizing campaignSelector within AdWords scripts?

I have been working on a script that aims to achieve the following tasks: Go through all the accounts in an MCC and pick out the ones with 'SEM' in their name. Go through the campaigns in a selected account and choose those that meet specific c ...

In what way can I indicate parsing "per dataset" using Chart.js?

I'm currently exploring the usage of the yAxisKey option in ChartJS while defining a dataset. However, I'm encountering difficulties in replicating this specific example from the documentation. Despite my efforts to search for issues related to y ...

Create a JavaScript script within a CSS file

I'm attempting to create this using only CSS: Codepen and I would like to achieve the same effect but solely with CSS. This is what my CSS looks like: .text{ --a: calc(var(--a);*0.82+(1.5-var(--b);)/10); --b: calc(var(--b);+var(--a);); transfor ...

Is there a method I can utilize to ensure functionality within Google Apps Script?

I encountered an issue when using innerHTML instead of getBody() and I am looking for assistance with debugging on apps-script as mine is not functioning properly. function findText(findme,colour,desc,rule_name) { var body = DocumentApp.getActiveDocum ...

What is the best method for clearing all session cookies in my React application?

Currently, I am working on a project using React. I am trying to find a method to automatically logout the user by deleting all of the session cookies in my React application. However, I have not been able to come up with a solution yet. Is there a way to ...

Retrieving Firestore information as a JavaScript object

I'm working on retrieving data from Google Firestore as a JavaScript object in Vue.js (3). It functions correctly when used within a V-for loop, but I also need to utilize the array in methods. How can I convert the Firestore data into a basic JavaScr ...

apply a border-radius to the top right corner only without affecting the other sides or background

https://i.sstatic.net/9YIiy.jpg I have been working on creating the top right triangle design shown in the image. However, I encountered an issue where applying border radius seems to affect all sides instead of just one as intended. Despite using border- ...

Dropdown box not displaying any choices

I developed a basic reusable component in the following way: Typescript (TS) import {Component, Input, OnInit} from '@angular/core'; import {FormControl} from '@angular/forms'; @Component({ selector: 'app-select', templa ...

WordPress Ignoring PHP Generated Elements When Processing Divs

Whenever I attempt to utilize the get_date function, it seems to disregard all div elements and instead places itself right after the header, at the beginning of the <div class="entry-content">. <div class="entry-content"> May 16, ...

Maintaining the image's aspect ratio using the Next Image component

Currently, I am using Next's Image component to display a logo. Although the image itself is 1843x550 px, I have specified the width and height properties to adjust it to fit within a space of 83x24 px. However, due to a slightly different aspect rati ...

Node.js: Error - Module 'html' not found

Currently, I am utilizing Node.js and attempting to exclusively serve HTML files without any Jade or EJS engines. Below is the code for my entry point (index.js): var express = require('express'); var bodyParser = require('body-parser&apo ...

Exploring the integration of data from two Firestore collections using JavaScript

I manage two different types of collections, one being called CURRENCY-PAIR and the other Alerts. The collection CURRENCY-PAIR includes the following information: Currency-Pair Name Currency-AskPrice Currency-BidPrice On the other hand, the Alerts colle ...

Avoiding JavaScript onclick event using JSON information

Here's a situation I'm dealing with: I have a button created using PHP that triggers a JavaScript onclick event: <button onClick='edit(this, "<?php echo $this->result[$i]["type"]; ?>","<?php echo $quality; ?>", "<?php e ...

The <ul> tag is not receiving the correct styles and is not displaying properly

I have successfully integrated an input control and button into my table within the Angular 7 application. When a user inputs text in the control and clicks the add button, the text is appended to the <ul> list. However, the layout of the <ul> ...