React does not support having two :focus selectors on a single JSX element

I'm working with a React script that includes a specific element. I want to apply more than one :focus-within selector in CSS, but for some reason only the dropdown selector is being expressed when I focus on the element. Here's the code: React JS:

return (
    <div>
      <div className="blind"></div>
      <div className="menufocus" tabIndex={0}>
        <div className="menuicon">
          <FontAwesomeIcon icon={solid("bars")} />
        </div>
        <div className="dropdown">
          <div className="dropitem">HOME</div>
          <div className="dropitem">ABOUT</div>
          <div className="dropitem">NEWS</div>
          <div className="dropitem">ICONHOLDERS</div>
        </div>
      </div>
    </div>
  );

CSS:

  display: flex;
  align-items: flex-end;
  width: fit-content;
  height: fit-content;
  max-height: 1vh;
  transition: max-height 1s;
  overflow: hidden;
  flex-direction: column;
  flex-wrap: nowrap;
  align-content: flex-end;
  justify-content: flex-start;
  color: white;
}

.blind {
  z-index: 1001;
  opacity: 0.7;
  width: 100vw;
  height: 100vh;
  position: absolute;
  top: 0px;
  left: 0px;
  background-color: black;
  display: none;
  transition: all 1s;
}
.menufocus {
  z-index: 1002;
  position: absolute;
  top: 0px;
  right: 0px;
  display: flex;
  justify-content: flex-start;
  flex-direction: column;
  flex-wrap: nowrap;
  align-content: flex-end;
  align-items: flex-end;
  width: fit-content;
  height: fit-content;
}

.menufocus:focus-within .dropdown {
  max-height: 18vh;
}
.menufocus:focus-within .blind {
  display: block;
}

Thank you!

Answer №1

As stated in the official documentation:

The :focus-within CSS pseudo-class selects an element if the element itself or any of its descendants are in focus. Essentially, it targets an element that either matches the :focus pseudo-class directly or has a descendant matching :focus. This includes descendants within shadow trees.

In simple terms, the .menufocus element is only seeking for its children to be focused, and your .blind is signaling to this requirement. Just ensure that it becomes a child of the .menufocus.

Answer №2

Hey there, I've returned, the navigation menu was closed but when you click on the burger icon (those 3 bars), the output should resemble this with a noticeable blur effect in the background.

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

Incorporating Twilio with React JS

I'm currently working on integrating Twilio into a React project by following the steps outlined in this documentation: After cloning the GIT Repo as mentioned in the document, I attempted to install it using the following commands: git clone https:/ ...

Ways to decrease font size and insert a line break within a constrained input space?

I am facing an issue where the input box remains static with old numbers when it overflows, and newly typed numbers do not appear at all. <!DOCTYPE html> <html> <body> <input type="text" id="output-area" placehold ...

Employing regular expressions within Notepad++ to insert whole numbers into img src within table elements

I have a large table filled with numerous items that require individual images to be added. Let's take a look at the code snippet below. <tr><td><img src=".jpg" width=100 height=100/></td></tr> Although I could manually ...

Tips for personalizing the weekday title of Material-UI's DateRangePicker

I've been struggling for hours trying to customize the weekday titles in Material-ui DateRangePicker. Instead of displaying "S", "M",..., I want to show the titles as I desire. I attempted to customize the dateAdapter without succe ...

FadeOut/FadeIn Iframe Animation

Help needed with making an iframe fade in and out using jQuery. Something seems off with the code and I can't figure out why it's not working. Can anyone spot the mistake? HTML <body> <center> <div class="headbackground" ...

What is preventing this brief code from functioning properly? I am trying to extract a value from an input field and add it to a div element

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script src="//ajax.googleapis.com/ajax/libs/jque ...

Transforming the text color after clicking on it on Squarespace - here's how to do it!

How can I make text change color upon clicking in Squarespace? Where should I place the block id in the code to target a specific block? Check out the code snippet I've been experimenting with: <script> document.getElementById('chang ...

Private route displaying unexpected behavior when making API call

A snippet of code I have been working on is partially functioning (refer to the last paragraph for a detailed description): App.Js: export default function App() { const [isLoggedIn, setisLoggedIn] = useState(null); const logIn = () => { setisLogg ...

Create a layout using jquery-tokeninput

Currently, my project incorporates jQuery-tokenInput and everything is functioning properly. However, I now have the desire to customize the design of the results that are displayed. For example, I want to adjust the width or make any other design changes. ...

What could be causing the background to disappear when the window width is reduced?

Can someone please explain why, after reducing the width of the window on , there is no wooden background in the upper right corner? Thank you in advance. ...

What is the best way to transfer a property-handling function to a container?

One of the main classes in my codebase is the ParentComponent export class ParentComponent extends React.Component<IParentComponentProps, any> { constructor(props: IParentComponent Props) { super(props); this.state = { shouldResetFoc ...

Position the division at the location of the cursor for particular usemap components

Looking for a way to position a division on top of an image using a usemap. Interested in having the div only appear when the mouse hovers over a particular area, and at the precise location of the cursor. Came across some examples using jQuery, similar ...

Implementing an onClick function for Tabs in Ant Design

I used Ant Design to create tabs. In the second tab, there is a button that, when clicked, should trigger or change back to the first tab. Below is my code snippet: <Tabs onChange={this.tabClick} defaultActiveKey="1"> <TabPane tab={<span& ...

Tips for maximizing page layout efficiency without compromising on element visibility

What is occurring https://i.stack.imgur.com/Agjw6.gif The use of .hide() and .fadeIn(200) is resulting in a jittery effect that I would like to avoid. Desired Outcome When the user hovers over the menu icon, the menu icon should vanish the text "Pr ...

Combining text output using JavaScript, HTML, and Vue

Can you help solve this challenge of outputting concatenated text from a javascript code? The script in question draws a quarter circle that is proportional to the size of the bar and showcases the value of pi accurate to three decimal places. To display ...

Spacing between cards using Bootstrap

I have a collection of cards styled with Bootstrap and I am looking to add a left margin. I want the cards to be evenly spaced across the width. Right now, there is excess red on the right side that I want to remove... .azer { background: red; } .car ...

Error: Unable to access the 'secondary' property of an undefined object - encountered after updating Material-UI from version 4 to version 5

We recently completed an upgrade from MUI version 4 to version 5, and since the upgrade, our UI tests have been failing with the following error: TypeError: Cannot read property 'secondary' of undefined (I added comment to which line in code thi ...

Displaying current data when the page is initialized using chartjs-plugin-zoom

My genStarts chart component relies on the visible data of another chart (singleChart) to populate its view. I am currently utilizing the onZoomComplete and onPanComplete options to trigger my getVisibleValues function, which updates genStarts when zooming ...

HTML filtering using the <select> element

Is there a way to implement this script for options instead of buttons? The goal is to filter the HTML section, but it seems to not work with <option> tags. Instead of displaying the all class, it shows nothing. CSS .show { display: block; } .filt ...

Contrast between Identification and Category

As I delved into the topic of CSS :Class and ID, I couldn't discern any noticeable differences between them when I attempted the provided examples. <!DOCTYPE html> <html> <head> <style> #para1 { text-align:center; color:red; } ...