reactstrap Collapse is not showing up on mobile - reactjs

The website I'm working on has an issue where the collapsible menu that's supposed to show up when the screen size is too small is transparent. It still works, but it's not visible, which obviously isn't what I intended. I'm using reactstrap to make the collapsible menu but I haven't discovered a way to make it visible so far in my research.
Can someone please help me solve this issue? The file where this issue happens is here in the render method.
<Navbar expand="sm" className="mb-3 my-navbar">
<Container>
<NavbarBrand tag={RRNavLink} exact to="/"
className="my-navbar-brand">Writer</NavbarBrand>
<NavbarToggler onClick={this.toggle} />
<Collapse isOpen={this.state.isOpen} navbar>
<Nav className="ml-auto" navbar>
{isAuthenticated ? authLinks : guestLinks}
</Nav>
</Collapse>
</Container>
</Navbar>

Since you are not using a theme for your navbar, the CSS for the toggler button is not appearing. As a fix you can try to add a theme to the navbar, e.g., navbar-light and you will see that the hamburger button appears
<Navbar expand="sm" className="mb-3 my-navbar navbar-light">
Alternatively, you can add the CSS for which ever color of the stroke you prefer. Here is the CSS for the navbar-light hamburger button strokes:
.navbar-toggler-icon {
background-image: url("data:image/svg+xml;charset=utf8,%3Csvg viewBox='0 0 32 32' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath stroke='rgba(255,255,255, 1)' stroke-width='2' stroke-linecap='round' stroke-miterlimit='10' d='M4 8h24M4 16h24M4 24h24'/%3E%3C/svg%3E");
}

Related

White glitch background before turning black in React

I have a website mostly done with React-Bootstrap and I am kind of a beginner in this field. I want my background to be black in all the pages so I set it with background-color:black !important; in every page. I did a Navigation Bar with React-Bootstrap and now when I move through the pages, there is a white glitch before turning it to black.
I tried to put the style in html, to load it faster, changed the color in body with !important, even overridden the bootstrap variable for background-color but neither of these worked.
I know that the glitch between the pages would dissappear if I would use just React NavBar not Bootstrap one and I've tried it, but there is also a glitch when you reload the page and it bothers me.
Has anyone any idea what could cause it?
My navigation bar is pretty simple:
<Navbar className="navbar" expand="sm">
<Navbar.Brand className="logo" href="#home" >React-Bootstrap</Navbar.Brand>
<Navbar.Toggle className="toggle" aria-controls="responsive-navbar-nav" />
<Navbar.Collapse className="navbar-links" id="responsive-navbar-nav" >
<Nav className="ms-auto">
<Nav.Link className="navlink" href="home">Home</Nav.Link>
<Nav.Link className="navlink" href="documents">Documents</Nav.Link>
<Nav.Link className="navlink" href="about">About</Nav.Link>
</Nav>
</Navbar.Collapse>
</Navbar >
Later edit :
I tried in Google Chrome and it shows only sometimes ( 2-3 reloads), but still appears.

React Bootstrap or other library for in-canvas to off-canvas solution

My project is using React Bootstrap, however I'm struggling to find the equivalent to Foundation's in-canvas to off-canvas feature, where some piece of content is available in the normal flow of the page but then goes into an off canvas menu on smaller screen sizes. https://get.foundation/sites/docs/off-canvas.html#in-canvas-to-off-canvas
Does anyone know of any other React plugins that would be able to do the same?
For clarity, I'm trying to do this:
(Desktop)
(Mobile)
(Mobile opened menu)
Create a NavBar component with OffCanvas, which expands on small breakpoint (expands = hides menu icon).
Create Content2 component and put it on your in-canvas screen and in the OffCanvas component.
Use media query to toggle visibility of Content2 component in your in-canvas scree
App.js:
<Stack className="min-vh-100">
<Navbar expand="sm" className="px-3 bg-primary">
<Navbar.Brand href="#home">React-Bootstrap</Navbar.Brand>
<Navbar.Toggle aria-controls="basic-navbar-nav" />
<Navbar.Offcanvas
id="offcanvasNavbar"
aria-labelledby="offcanvasNavbarLabel"
placement="end"
>
<Offcanvas.Header closeButton>
<Offcanvas.Title id="offcanvasNavbarLabel">
Offcanvas
</Offcanvas.Title>
</Offcanvas.Header>
<Offcanvas.Body>
<Content2 />
</Offcanvas.Body>
</Navbar.Offcanvas>
</Navbar>
<Stack direction="horizontal" className="flex-grow-1 align-items-stretch">
<div className="bg-info flex-fill w-50 d-flex justify-content-center align-items-center">
Content 1
</div>
<div className="content2 w-50">
<Content2 />
</div>
</Stack>
</Stack>
css:
.content2 {
display: block;
}
#media screen and (max-width: 576px) {
.content2 {
display: none;
}
}
https://codesandbox.io/s/fancy-snow-w2ug5w

Right way of putting elements above Nav component? pushes the Nav elements to the side. React Bootstrap

Hi All, for the life of me, I've been stuck in this dilemma for days. I'm building a new website for my father in law's restaurant & built it in React so I can make the Menu dynamic & bootstrap.
I got the Nav bar JUST how I wanted it except for this last step. I want to add text on the top left which ends up pushing the navbar to the right. I did try to get it hovered in the top left but then it covers my ability to click on "Menu" or "Events". On top of that, I have been unsuccessful in getting text in the top right where I want to put phone numbers. It's like the image blocks the text from stretching to the right, any suggestions?? I couldn't find anything similar to this on google.
class Navigation extends React.Component {
render() {
return (
<Navbar variant="light" expand="md" >
<Container>
<Navbar.Brand href="/" className="d-md-none">
<img src={logo} height="55px" alt="Mikes Pizzeria" />
</Navbar.Brand>
<div id="navContent">Italian Quisine at its Best</div>
<Navbar.Toggle aria-controls="responsive-navbar-nav" />
<Navbar.Collapse id="responsive-navbar-nav">
<Nav className="mx-auto align-items-end nav-fill w-100">
<Nav.Link href="/menu">Menu</Nav.Link>
<Nav.Link href="/events">Events</Nav.Link>
<Nav.Link href="/">Social</Nav.Link>
<a className="d-none d-md-block"href="/"><img src={logo} alt="Mikes Pizzeria" height="100px"/></a>
<Nav.Link href="/">VIP Rewards</Nav.Link>
<Nav.Link href="/about">About</Nav.Link>
<Nav.Link href="/">Order Online</Nav.Link>
</Nav>
</Navbar.Collapse>
CSS
.navbar{
background-color: rgba(210, 194, 158, 0.7);
margin-bottom: 30px;
}
#navContent{
font-size: 20px;
position: relative;
float:none;
overflow:hidden;
margin:20px;
}

React Ternary Operator Prevent Repeating Code with Styled components?

So I'm using styled components and found the only way to trigger my function is with a ternary operator that wraps my entire navbar component. The problem is I have to recopy the entire component code into the : statement which basically means I'm writing my nav component code twice just to get the ternary to work properly.
Is there a way to not repeat it and write the ternary with the least amount of code?
So here's my code issue
return (
<>
// If scroll is true, I want to add this active prop onto my <Nav>
{scroll ? (
<Nav active click={click}>
<NavbarContainer>
<NavLogo to="/" onClick={closeMobileMenu}>
<NavIcon />
EXPLOR
</NavLogo>
<MobileIcon onClick={handleClick}>
{click ? <FaTimes /> : <FaBars />}
</MobileIcon>
<NavMenu onClick={handleClick} click={click}>
<NavItem>
<NavLinks to="/">Home</NavLinks>
</NavItem>
<NavItem>
<NavLinks to="/images">Images</NavLinks>
</NavItem>
<NavItem>
<NavLinks to="/products">Products</NavLinks>
</NavItem>
</Nav>
:
// If the scroll is false, I remove the active prop from my nav
(
<Nav click={click}>
<NavbarContainer>
<NavLogo to="/" onClick={closeMobileMenu}>
<NavIcon />
EXPLOR
</NavLogo>
<MobileIcon onClick={handleClick}>
{click ? <FaTimes /> : <FaBars />}
</MobileIcon>
<NavMenu onClick={handleClick} click={click}>
<NavItem>
<NavLinks to="/">Home</NavLinks>
</NavItem>
<NavItem>
<NavLinks to="/images">Images</NavLinks>
</NavItem>
<NavItem>
<NavLinks to="/products">Products</NavLinks>
</NavItem>
</Nav>
}
</>
The whole point is so I can trigger this active prop from my styled component
background: ${({ active }) => (active ? "#141414" : "transparent")};
But as you can see I had to copy my entire component code twice because the <Nav> that has the active prop wraps around my entire code.
Is there an easier way to toggle the active prop with styled components without having to recopy my entire navbar in the : or statement?
Assuming active is a booelan you can smply set active={scroll } like so
<Nav active={scroll} click={click}>
.....
</Nav>

Nav not collapsing when a NavItem is selected on mobile devices

I'm building a navbar that is expected to be responsive when it switches to mobile devices. In other words, collapse when mobile, then when the navitems are selected / clicked, it should route to the path and collapse all navitems to a toggle-style bar. However, below a snapshot of what I got and it's associated code:
CODE:
render() {
return (
!this.state.isAuthenticating &&
<div className="App">
<Navbar fluid collapseOnSelect>
<Navbar.Header>
<Navbar.Brand>
<LinkContainer to="/">
<a>
<img src={logo} alt="logo" height="70" width="75"/>
<p>hybriData</p>
</a>
</LinkContainer>
</Navbar.Brand>
<Navbar.Toggle />
</Navbar.Header>
<Navbar.Collapse>
<Nav pullRight>
{this.state.isAuthenticated
? <Fragment>
<LinkContainer to="/settings">
<NavItem>Settings</NavItem>
</LinkContainer>
<NavItem eventKey={1} onClick={this.handleLogout}>Logout</NavItem>
</Fragment>
: <Fragment>
<LinkContainer to="/About Us">
<NavItem eventKey={2}>About Us</NavItem>
</LinkContainer>
<LinkContainer to="/Contact">
<NavItem eventKey={3}>Contact</NavItem>
</LinkContainer>
<LinkContainer to="/works">
<NavItem eventKey={5}>Works</NavItem>
</LinkContainer>
<LinkContainer to="/signin">
<NavItem eventKey={6}>SignIn</NavItem>
</LinkContainer>
</Fragment>
}
</Nav>
</Navbar.Collapse>
</Navbar>
</div>
);
}
I also integrated some of this solution react-bootstrap how to collapse menu when item is selected using the expanded and onSelect props of the navbar and nav's activeKey and onSelect props to achieve desired functionality but to no fruition. How can I implement desired functionality of having all navitem's collapsed when any path(s) is navigated to , clicked / selected? Thank you
Here is a simplified working example. It's about the order of items. If you look at the bootstrap CSS, you see some styles like
.nav > li {
position: relative;
display: block;
}}
The > symbol is a selector that selects all immediate descendants or children (first 'wrap layer' only, not applied to second 'wrap layer'), namely if you have
<ul class="nav">
<div>
<li>something</li>
<li>something</li>
</div>
</ul>
the styles are not applied, while
<ul class="nav">
<li>something</li>
<li>something</li>
</ul>
works. In your case, try replacing the <Fragment> with <Nav> and remove the outer <Nav>.
Another part you may want to modify is the LinkContainer wrapping the NavItem part. Usually we have <li> (NavItem) wrapping <a> (Link) but not the other way round.
Although react-bootstrap makes the code easier to read, it abstracts the details and may be harder to get something working. If you have difficulty with react-bootstrap, I suggest you to stick with pure bootstrap elements. The codes are slightly longer but the appearance is the same. You can follow w3schools to use bootstrap styles.

Resources