Creating a full-page scrollbar in React when a component goes beyond the viewport

I'm currently working on an app that has a layout like this:

https://i.sstatic.net/w3fty.png

The middle component extends beyond the page, which is why I need a scrollbar to navigate down to it. However, I'm struggling to implement a regular whole page scrollbar. I tried attaching it directly to the middle component, but my goal is to have a standard scrollbar for the entire page.

Here is a snippet of my app.js file:

import React, { Component } from 'react';
import OysterView from './components/OysterView.js'
import './uikit/uikit.css';
import './App.css';
import logo from './uikit/assets/images/hrm-white.svg';

class App extends Component {
  render() {
    return (
    <div className="App">      
      <div className="App-header">
        <header>
          <img src={logo} className="App-logo" alt="HRM"/>
        </header>
      </div>
      <div className="OysterView">
       <OysterView />
       </div>
    </div>
    );
  }
}

export default App;

I've experimented with various CSS properties to address the issue, including setting overflows and heights in the .App class. However, none of these solutions seem to recognize that the component extends off the screen, making it impossible to scroll down to <OysterView />. I've also attempted modifying the HTML tag itself, but to no avail.

  .App {
  overflow-y: scroll;
  background-color: #fafafa;
 position: fixed;
  height: 100vh;
  width: 100vw;
  z-index: -2
}

Adding a height to the .App class causes content to be pushed down, negating any progress. Additional attempts in the index.css stylesheet have resulted in a non-scrollable scrollbar. At this point, I'm out of ideas. Does anyone have suggestions on how to approach this? Perhaps utilizing z-index on .App?

Answer №1

To avoid scrolling the component itself, simply enlarge its container to cover the entire screen, causing the scrollbar to appear on the right side of the window.

  .modal-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba( 0, 0, 0, .5 );
    overflow-y: scroll;
  }
  
  .modal-content {
      background: red;
      margin: 20%;
      height: 2000px;
  }
Page content
<div class="modal-container">
  <div class="modal-content>
    Modal content
  </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

temporary solution to address IE compatibility issue with jquery

Due to lack of placeholder support in Internet Explorer for input elements, I am attempting to implement a workaround using jQuery. My goal is to have the field value initialized on page load. While I have successfully achieved this on field focus, I&apos ...

Eliminating an index from a JSON array using Typescript

I'm working with a JSON array/model that is structured as follows: var jsonArray = [0] [1] ... [x] [anotherArray][0] [1] ... [e] My goal is to extract only the arrays from [0] to [x] and save them into their ...

Switching from webpack/CRA to snowpack resulted in an error: Uncaught SyntaxError - module X does not export Y

Could you please assist me in deciphering the root cause of the error message displayed below? I am currently working on migrating a project to Snowpack, after previously using create-react-app. Within this project, I am utilizing a library called react-k ...

Achieve full implementation of ng-repeat within an angular directive

Can you explain how the custom angular directive 'myscroll' is able to detect and interact with the ng-repeat elements that are dynamically created in the code snippet below? <myscroll> <div ng-repeat="item in items">{{item}}< ...

Is there a method for manually determining a map's LatLngBound based on the center point and zoom level

Currently, I am attempting to display a Google Map using the react-google-maps library. Before the map is completely loaded, I am retrieving the user's current location using the geolocation.navigator function. However, I am facing a challenge in det ...

Cannot assign value to property x on y as it is not an object - dealing with Multidimensional Arrays

I'm experimenting with creating a multidimensional array that looks like this: var minutes = []; for (let i = 1; i < 10; i++) { minutes.push(i); } var works = [{ startTime: 80000, endTime: 150000 }, { startTime: 200000, endTime: 400000 ...

Creating a dynamic feature to add a row at the bottom of a table

I am currently working with JavaScript in the context of an AngularJS application, attempting to insert a row at the bottom of a table that shows the total sum of a specific column. Here is the code snippet I am using: var table = document.querySelecto ...

When importing modules in node.js, the presence of a function can overwrite another function even if it

Within this code snippet, I am utilizing Express.js. //index.js app.use('/',routes()); //app/routes.js module.exports = function() { express = require('express'); const loggedUserProfileController = require('../controller ...

Dynamic TextField sizing

I am currently facing an issue while displaying data on a webpage using TextField component from @material-ui. Each record of data has varying lengths, making most values appear unattractive (occupying only 10% of the textfield width). Even though I am ut ...

Trouble with Two Divs Layout

My website layout includes links on the left side of the page within a floating div, with content on the right side in another floating div. However, I'm facing an issue where the content moves below the links when the page is resized. I attempted to ...

Can we determine if a user has accessed a link by opening it in a new tab?

Is there a way to distinguish if a user on your website opens another link (also to your website) in a new tab from them just clicking on the link normally? Whether it's through javascript, server-side processing, or any other method. I assume that d ...

Is your preference selecting made a breeze by dragging the input field?

Looking to create a form that allows users to indicate their preference between Option A and Option B by dragging a slider. I know there must be a library out there that already does this, but I can't seem to figure out what it's called to searc ...

Tips on finding the right parent object by utilizing the information stored in the nested array

I have a collection of objects structured as follows: var items = [ { itemId: 0, itemQuantity: 10, attributes: [ { type: "Size", value: "Small" }, { type: "Color", value: "Black" } ] }, { itemId: 1, itemQuantity: ...

Add some hues to the icons

I am a beginner when it comes to CSS and jQuery. My goal is to color in an icon, similar to Instagram's heart icon which turns red when double-tapped. Currently, I am using Font Awesome for this purpose. However, I am struggling to fill the color as ...

The functionality of two-way binding in a distinct controller is not functioning properly when integrated with angular-wizard

I've been working hard to integrate this amazing wizard controller into my project: However, I've hit a roadblock with two-way binding not functioning as expected outside of the <section> attribute: http://plnkr.co/edit/N2lFrBRmRqPkHhUBfn ...

Error Encountered during Deployment of Custom React App on Heroku due to Fetch API Issue

After developing a small app using React without CRA, I successfully deployed it to Heroku. However, I encountered an issue where a static JSON file that I created isn't fetching properly (it works fine on my local machine). Upon encountering this pr ...

What is the reason behind the progress element maintaining its vertical space despite being reduced in height?

When you decrease the height of a progress element, it visually appears smaller but still takes up the same amount of space as if it were at its original height. div{ border: 1px solid blue; } When the progress is bigger, the div expands accordingly & ...

Manipulating rows [using an input field] within a table

As someone new to JavaScript, I tried my hand at coding the following piece after tweaking a tutorial I stumbled upon. The aim was to have rows with input fields added and removed within a table, but unfortunately, nothing happens when running the code. ...

Is there a way to always keep an element positioned directly above a fluid image that is perfectly centered?

My current project involves creating an overlay to display a fluid image of any size. The challenge I'm facing is how to consistently position the close button 30px above the image and flush with its right edge. The catch is that the container doesn&a ...

The mp4 video on the website will only load if the Chrome developer tools are activated

Whenever I try to play the video set as the background of the div, it only starts playing if I refresh the page with Chrome dev tools open. HTML: <div id="videoDiv"> <div id="videoBlock"> <img src="" id="vidSub"> <video preload="prel ...