gist-react: containing gist within a scrollable div

Struggling to contain a gist within a div with scrollbars on my next.js site using gist-react. It seems like my CSS is being overridden when the gist loads from the underlying dependency. Is there a way to achieve this without modifying the dependency itself?

@/projects/[slug]/page.jsx

import styles from "./singleProject.module.css"
import { Gist } from 'gist-react';
...
<div className={styles.gistContainer}>
    <Gist gistId="2223329" />
</div>

@/projects/[slug]/singleProject.module.css

.gistContainer{
    width: 45%;
    height: 30%;
}

Noticing CSS overrides within the iframe body in the module.

/node_modules/gist-react/dist/Gist.js

React.useEffect(() => {
    if (!ref.current) return;

    const $iframe = ref.current;

    $iframe.srcdoc = `
      <style>
        *{box-sizing: border-box; overflow-y: hidden;}
      </style>
      <base target="_blank">
      <script src="${url}"></script>`;
  }, [url]);

return (
    <iframe
      ref={ref}
      onLoad={() => {
        if (!ref.current) return;
        const $iframe = ref.current;
        const innerHeight = $iframe.contentDocument?.body.scrollHeight;
        $iframe.style.height = String(innerHeight) + 'px';
      }}
      style={{ border: 0, width: '100%' }}
      id={iframeId}
    /gt;
  );

Multiple attempts at editing the dependency with no success in achieving the desired height or scrollbars.

React.useEffect():

  • removed overflow-y: hidden. That added unintended scrollbars.

return Statement:

  • Removed the height styling from the $iframe, also from the $iframe.contentDocument?.body

  • Added maxHeight to the $iframe, also the $iframe.contentDocument?.body

Trying

.gistContainer iframe{ width: 45%;height:30%;max-height:30%}
in the CSS but the container dimensions were not preserved after the dependency adjusted the iframe styling.

Other unique references:

  • how-to-change-height-of-a-dynamically-embedded-gist Tested & unsuccessful
  • make-gist-embed-scrollable Tested & unsuccessful

Answer â„–1

@/projects/[slug]/singleProject.module.css

.gistContainer iframe{
    width: 100% !important;
    height: 100% !important;
    max-height: 100% !important;
}

This resolution addresses a portion of the issue at hand.

Below is the method to adjust the scrollbars:

/node_modules/gist-react/dist/Gist.js

$iframe.srcdoc = "\n      <style>\n        *{box-sizing: border-box; overflow-y: auto;}\nbody::-webkit-scrollbar {display: none;}      </style>\n      <base target=\"_blank\">\n      <script src=\"".concat(url, "\"></script>");

I decided to adhere to the existing code formatting style, which appeared to resolve my problem satisfactorily.

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

Exploring the use of jQuery autocomplete to retrieve data attributes

Looking to retrieve additional data-attributes from the Mapbox API. The autocomplete plugin I implemented can be found here. (Utilizing Python/Django for backend) My goal is to send extra information such as country code, city, and country to my databas ...

Sustaining authentication in React using Firebase

I successfully integrated firebase authentication for email login and registration into my React app. Now, I'm looking to enhance it with a "remember me" checkbox feature. Although I have experience with the onAuthStateChanged listener and understand ...

Building SVG components in React with TypeScript and styling them using SCSS

I've been experimenting with using Webpack to import SVG files as components in React Typescript. However, I'm running into trouble when it comes to styling the SVGs with SCSS. I've tried targeting a custom attribute in my CSS selector, but ...

What is the best way to showcase a value in JavaScript using CSS styling?

I'm looking to customize the background, font style, and outline for both open and closed elements in the code snippet below: a.innerHTML = "We are Open now now."; a.innerHTML = "We are Closed, arm."; Additionally, I want to appl ...

dismiss data and button for closing notification bar

I am currently using a notification bar at the top of my website, instead of a modal. I am wondering if it is possible to click the X (close-button) and have the notification bar disappear. I attempted to use data-dismiss but it did not work. Also, how can ...

Use JavaScript to gather various data forms and convert them into JSON format before transmitting them to PHP through AJAX

My understanding of JSON might be a bit off because I haven't come across many resources that discuss posting form data via JSON/AJAX to PHP. I often see jQuery being used in examples, but I have yet to delve into it as I've been advised to firs ...

Is there a way to customize the default settings for a blueprint’s menu item?

https://i.sstatic.net/aNeJY.jpg In my react project, I implemented the Menu using MenuItem from '@blueprintjs/core'. The issue I encountered is that when hovering over a Menu item with children, they open from the right side. Is there a way to m ...

How can I verify the presence of links in an input field and determine its character count?

I've dived into coding for this project and I'm making progress. Here are my objectives: 1) Verify the length of URLs entered in a field and reduce each link's length by 20 if it exceeds 20 characters. 2) Calculate the remaining characters i ...

The focal point of a Three JS rotation

My goal is to rotate the geometry around a pivot point and set that as the new definition of the geometry. I want the current rotationZ to become the new rotationZ 0 without having to keep editing the rotationZ. This way, when I create a new rotation task ...

What is the best way to save the outcomes of several asynchronous $.get calls into an array?

I have a challenge where I need to retrieve data from an API for each item in an array, and then store that data in another array for further processing. However, I suspect the issue lies in the asynchronous nature of the requests, as the data may not be ...

Can a virtual host proxy utilize an external IP address?

Currently, I have three node apps running on the same server but with different localhost ports. My goal is to create a router that acts as a proxy for each app and then place this proxy in a virtual host. While I am currently testing this setup on my loca ...

The deconstructed state does not get refreshed within the setState callback

Encountering an issue where breaking down a component's state is causing it to not update within setState: state = { value: 'test', values: ['a', 'b', 'c'], }; ... const { value, values } = this.state; ...

When sending a file to a node.js/express.js server using jsPDF, the file is being saved without an

My React component is designed to collect user data and use it with jsPDF to create a downloadable PDF file. let doc = new jsPDF(); doc.save() Everything works smoothly, and the file is saved with the .pdf extension as expected. The challenge arises when ...

What is the reason for the difference in width between Bootstrap-5 row and regular div blocks?

My code may seem simple, but I have encountered an issue with it: <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="99fbf6f6edeaedebf8e9d9acb7abb7a9">[email protected]</a ...

The compatibility issues with the textarea and text-indent: placeholder feature on EDGE are causing functionality problems

I'm facing a peculiar problem with placeholders when using the Edge browser. In my current project, I need to implement a textarea with a specific text-indent property. However, on Edge, the placeholder text appears displaced more than expected. To h ...

The div is not displaying the conditional styling as expected

I need help with mapping an array of cards wrapped in a div. I want the first, second, second-to-last, and last divs to go on a new line or take up the entire row. My project is in Vue3 and I'm using the PrimeVue component library. <div class=" ...

jQuery UI DatePicker: without any styling, no picking dates

I'm struggling to configure a jQuery UI DatePicker. I moved the development-bundle folder contents to the directory res/jqueryui and initialized two datepickers as shown below: <script src="res/jquery-2.1.0.min.js"></script> <script sr ...

Retrieving Text Between HTML Tags Using jQuery

Disclosure: I am fully aware of the messy HTML code in this legacy application. Unfortunately, due to its extensive dependencies, making any changes to the HTML structure is not feasible. Despite the circumstances, here is the code snippet at hand: <t ...

Error encountered while executing npm run dev in the node module for next.js: token not recognized

Setting up a new Next.js project has been my latest task. I followed the instructions in the documentation exactly and used this command line: npx create-next-app@latest nextjs-blog --use-npm --example "https://github.com/vercel/next-learn/tree/maste ...

Employ node's gm library in combination with promises and buffers

Using gm with Bluebird has been a bit tricky for me. Initially, I tried this approach: var gm = require('gm'); var bluebird = require('bluebird'); gm = bluebird.promisifyAll(gm); However, when attempting to execute the following code: ...