Tips for concealing the Grommet SideSplit element

My React/redux app utilizes the grommet ux framework with a specific structure:


    <App className="gol">
      <Article>
        <GLHeader />
          <SideSplit active={props.nav} onResponsive={checkMobile} >
             <GLNav />
             <GLBoard />
          </SideSplit>
        <Footer colorIndex="neutral-1-a" justify="center">&copy;&nbsp;2016 </Footer>
      </Article>
    </App>

I want to have the <GLNav /> component hidden by default, only displaying when a Settings icon is clicked to allow the <GLBoard /> component to take up the screen. Through Redux state management, I control the toggle of the active prop and manage a CSS class for the <GLNav /> component. The CSS rules dictate that the width will transition to 0 to show/hide the NAV section:

.hide{
  width: 0 !important;
  transition: width .3s ease-out;
}
.show{
  transition: width .3s ease-out;
}

This setup functions flawlessly in Chrome. However, Safari presents an issue when the SideSplit element is not in mobile mode (screen width above 750px) - even if the active prop is false and the .hide class is applied, the <GLNav /> retains a width value. Only when reducing the width below 750px does grommet add a `hidden` class, effectively concealing the <GLNav />.

Below is the code snippet for the <GLNav /> component:

const GLNav = props => {
    return(
      <SideBar colorIndex="neutral-1-a" className={props.nav}>
        <Header pad="medium" justify="between">
          <Title>
            Settings
          </Title>
          <Button icon={<Close />} onClick={() => props.actions.toggleNav()} />
        </Header>
     </SideBar>
  )
}

Answer №1

While the current method works, I think there's a more efficient way to achieve your goal without directly manipulating CSS.

Have you explored the Animate utility in Grommet?

This tool allows for a pure React approach to hiding elements without relying on CSS (it utilizes react-addons-transition-group in the background).

In your scenario, I would suggest something like this:

export default MyComponent extends Component {
  state = { navActive: false }

  render () {
    const { navActive } = this.state;

    let navNode;
    if (navActive) {
      navNode = (
        <Animate leave={{"animation": "slide-left", "duration": 1000}}
          visible={true}>
          <GLNav />
        </Animate>
      );
    }

    <App className="gol">
      <Article>
        <GLHeader />
          <SideSplit active={props.nav} onResponsive={checkMobile} >
             {navNode}
             <GLBoard />
          </SideSplit>
        <Footer colorIndex="neutral-1-a" justify="center">&copy;&nbsp;2016 </Footer>
      </Article>
    </App>

  }
}

Answer №2

After successfully implementing my suggestion as a solution, I am posting it here as an answer.

We can set the maximum width of the .hide class to 0 by adding the following CSS:

.hide{
  width: 0 !important; /* You may no longer need !important */
  max-width: 0;
  transition: width .3s ease-out;
}

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

I'm having issues with running my npm install -g react-native-cli

Unfortunately, I am unable to run react-native on my mac due to a permission issue. Despite my attempts to rectify this problem and obtain the necessary permissions, I have been unsuccessful. npm WARN checkPermissions Missing write access to /usr/local/ ...

Is it feasible to make Twitter's Typeahead plugin have an initial slide down or fade in effect?

Does anyone have an easy way to make the dropdown from Twitter's typeahead jQuery plugin initially slide down or fade in? I'm trying to animate the size of the dropdown menu when it adjusts, but even a simple fade or slide in would be fine. I pre ...

When utilizing hover and click functionalities within Material-UI ToolTip, it can lead to difficulties when attempting to close

I have successfully implemented hover and click functionality separately in material ui Tooltip. Now, I am looking to combine both functionalities. Specifically, when I hover over the tooltip, it should open. Then, if I click on the tooltip, it should sta ...

React encountered an error: Unable to destructure the property 'id' of '_ref' as it has been defined

After spending several hours trying to solve this issue, I am completely stuck. The console shows that the patch request successfully updates the information, but then my map function breaks, leading to a blank page rendering. Here is the problematic comp ...

Tips on how to dynamically update the icon and label once a step is completed in Material-UI's core Stepper

import React from 'react'; import { makeStyles } from '@material-ui/core/styles'; import Stepper from '@material-ui/core/Stepper'; import Step from '@material-ui/core/Step'; import StepLabel from '@material-ui/c ...

Is there a way to prevent the CSS selector ".a.b" from targeting ".a.b.c"?

Recently, I came across some coding that looks quite similar to the html snippet provided below. <div class="a b">how_can_i_select_ab_only</div> <div class="a b disabled">how_can_i_select_ab_and_disabled_only</div> My goal is to ...

Executing a series of actions in React redux synchronously

https://i.sstatic.net/QnZew.png Within the store, there exists an array named visited:[]. Inside a function titled changeInfo, the first task is to clear the array followed by adding an item to it. const changeInfo = (value) => { dispatch(clearVis ...

What is causing the issue with Shallow routing in Nextjs?

I've been experimenting with Shallow routing in Next.js to update the state in the URL without actually navigating to a new page, but I'm encountering unexpected behavior. In the scenario outlined below, I start on the home page using the URL: l ...

FancyBox: Struggling to adjust dimensions accurately

Currently using Fancybox 1.2.6 in conjunction with JQuery 1.2.6, Sample Code: <script type="text/javascript> $(document).ready(function() { $("a.iframe").fancybox({ 'width' : 300, 'hei ...

Establishing secure communication between React frontend and Node backend systems

Having some trouble passing a session from my Node backend to React frontend. Feeling a bit lost in what I don't know, so any help is appreciated. This is the current issue: Backend route snippet: app.get('/account', ensureAuthenticated, ...

Registered symbol appears as random characters in Internet Explorer web browser

When working on my HTML code, I encountered an issue with displaying a registered sign. While the entity code I used worked perfectly in Chrome, Internet Explorer showed an 'A' character before the sign. I tried various codes like -&#174; - ...

What is the best way to update setState when triggering an onChange event?

Here is the code snippet for a React component that handles cryptocurrency selection: import React, { Component } from 'react'; import { Select } from 'antd'; import { connect } from "react-redux"; class SelecionarCrypto extends Compo ...

Modify the text in a paragraph by clicking on a link using JQuery and HTML

I'm attempting to implement a straightforward action, but I'm facing some challenges. My navigation bar consists of a few links followed by a text section. What I aim for is that when I click on a link, the paragraph of text should change to refl ...

What is the best way to save input values into a Database?

Hey there, I'm a beginner looking to figure out how to send a post request from this input to the database. Can someone guide me on what steps I need to take to make this happen? import { useState, useEffect } from "react"; import axios from ...

Tips for centring navigation horizontally and making it responsive using CSS

Is there an effective way to horizontally center the navigation within a div using responsive CSS? HTML: <nav id="centermenu"> <ul> <li><a href="#">Business</a></li> <li><a href="#">Spec ...

Issue with displaying PDF files on Google Chrome due to a software glitch

Recently, I encountered a puzzling issue on Google Chrome. I am not sure if the error lies with Google or within my code. When I set the div as display: none; and then show it again, the PDF view only shows a grey background. However, if I zoom in or out, ...

Is it possible to incorporate a similar box on a webpage?

I am trying to find a way to add a similar box to a webpage like the one shown in this image. The design I am referring to is from Reddit's theme, but I would like to know how to create a box with a different color and then have another box next to i ...

Remove the opacity setting from a transparent box that covers the entire page

I find that real code tends to be more complex, but this snippet does a good job of highlighting the issue at hand. In my setup, there's a background video playing (in this case, just as the background), and on top of that sits a transparent watch fa ...

Having trouble getting the focus-within CSS pseudo-class to work with an HTML label

I'm attempting to create a dropdown menu with checkboxes inside the dropdown area. Below is the code snippet I am using: .search-box { color: black; width: 450px; } .search-box .fake-tb { display: flex; flex-wrap: nowrap; background: #f ...

What is the best way to delay the fetch operation until the redux state is ready?

When fetching data from a database, I need it to differ depending on the user. I attempted to achieve this by passing the userid as a query parameter. However, the id is stored in a redux state which takes some time before it is available. Despite using if ...