focus-within | Style elements when they are focused or contain | Frontend Framework library
kandi X-RAY | focus-within Summary
kandi X-RAY | focus-within Summary
Focus Within lets you style elements when they are focused or contain a focused element, following the Selectors Level 4 specification.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of focus-within
focus-within Key Features
focus-within Examples and Code Snippets
Community Discussions
Trending Discussions on focus-within
QUESTION
I use the pseudo-class:focus-within on my menu to show the sub-menu on click, but it shows it for a second, and then the sub-menu disappears. There is no problem when I use pseudo-class: hover, I just have the problem with focus-within.
li class="has-sub-menu" when I click on it to show the ul class="sub-menu" it get disappear.
Can anybody help me, please?
here are my HTML and CSS codes.
...ANSWER
Answered 2021-Jun-14 at 04:25The code uses anchor tag elements so as to have a focusable element within the li elements.
The problem with this, alongside the empty href attribute, is that it focuses (so we see the sub menu) but then immediately moves to the link (which is empty) and unfocuses. So we see a flash of the sub menu then it disappears.
So what can we do to put a focusable element into the li element?
MDN has this advice:
onclick events Anchor elements are often abused as fake buttons by setting their href to # or javascript:void(0) to prevent the page from refreshing, then listening for their click events .
These bogus href values cause unexpected behavior when copying/dragging links, opening links in a new tab/window, bookmarking, or when JavaScript is loading, errors, or is disabled. They also convey incorrect semantics to assistive technologies, like screen readers.
Use a
button
instead. In general, you should only use a hyperlink for navigation to a real URL.
So this snippet uses the code given in the question, changing the a elements for buttons, and removing the background-color and border from the button styling.
QUESTION
I do not understand what I am doing wrong (Im a backend guy though). Using Tailwind on VueJS, This menu wont appear above the DIV. I have tried z-index and everything but nothing will make it appear. When I try and force the menu to the front of the screen it wont appear. I have no idea what I am doing wrong.
...ANSWER
Answered 2021-Jun-02 at 19:51The footer
overflow-hidden
set, which cuts off any elements that extend out of the border of the
. Since your menu should extend out the top of the
, this isn't what you want. Removing this utility appears to fix the issue.
When debugging designs with lots of these Tailwind classes all over the place, it can be helpful to look at things in your browser DevTools to avoid being overwhelmed or missing things.
z-index
can be tricky to work with, especially since it's commonly misunderstood. A lot of the time, you shouldn't need to use z-index, so seeing if other strategies work could reduce complexity and make your sites more resilient. For more information on z-index, check out Josh W. Comeau's excellent blog post.
QUESTION
i have a huge problem with my project in react. I'm trying to update the libraries on my project but seems something wrong happens.
This is the package.json
...ANSWER
Answered 2021-May-26 at 12:48A few developers are now slowly getting this hopefully temporary problem when they update their projects.
For example: https://github.com/facebook/create-react-app/issues/11012
Recommendation is to leave this on the todo list, and wait a few days while the package developers fix this (at least for the packages that already have been notified)
Then run audit fix
again
In the meantime, one error in particular the 'high' severity one...
QUESTION
I'm making a custom that contains an , and my goal is to remove the natural outline/border from the and place it on the containing such that it still looks natural when focussed, however, it seems that I am not getting the natural outline appearance and instead it looks like the outline is placed on the outside of the div...
Natural input element
My custom div containing the input
Is there something that can be done to achieve the natural outline look?
I have used outline: 5px auto -webkit-focus-ring-color;
for the styling on the
ANSWER
Answered 2021-May-25 at 09:49You can try giving it a negative outline-offset
such as outline-offset: -1px;
It's not pixel perfect, but it does look a bit more like built-in style outline on Chrome:
But do bear in mind that it might vary for different devices. For me -1px
looks the best.
QUESTION
I am trying to make floating input label which will float top when the input text area is focus. However, I ran into a problem where I can't click the input field because label is block me. There is small portion that I can press which is hard. Below I have shown my important code.
...ANSWER
Answered 2021-Apr-28 at 17:07If the label is blcoking you from clicking on your textarea, and you would not want to click on the label for any reason, you can use:
QUESTION
I need a hidden delete button to appear and work when a input is focused using markup and CSS in Svelte.
I got it all working in browsers for OS X and Raspberry Pi OS (Chrome, Chromium, Safari and Firefox). Click here to see it.
The problem is that the button appears but is not working in any of my iOS browsers (Safari or Firefox). Nothing is happening when the delete button is clicked.
I've tried following:
- focus-within works on Android browser but not iOS
- How to make a button appear only when input is focused
Here is the markup...
...ANSWER
Answered 2021-May-18 at 13:23With a little bit of debugging, it turns out, that by attempting to click on a button, you actually click on a
QUESTION
When i run npm audit on my react project i get the following long list of issues.
...ANSWER
Answered 2021-May-23 at 00:27I had posed this question couple of weeks ago here.
You can overcome this by forcing a resolution of postcss to ^8.2.10
temporarily. I wouldn't anyway worry much as a patch is being done as we speak, so it's just going to be a matter of time before it gets resolved.
QUESTION
I am working on a new component for textareas and want to give them the ability to do three things; autofocus
, debounce
(still working on that) and autogrow/resize
based on value.
I have been given a base component on which to work with and there are a few computed properties that I have been given that I'm not too familar with. From what I understand though, I shouldnt need them to be able to make these new props work.
I have the autofocus working perfectly as a passed prop, but the autogrow/resize has been giving me some trouble. In an isolated instance, I can get it to work, but passed as a prop with this basecomponent, I cannot managed to get it working.
When I try and add :value="value"
for the v-model to work, I get an error:
:value="value" conflicts with v-model on the same element because the latter already expands to a value binding internally
I imagine this is because it's clashing with the v-model="model"
above, but I'm not sure what to do with it from there.
I've attached the version that does work at the bottom.
My question is, what am I doing wrong in the CcInput-App.vue relation that won't make it work like the isolated version below?
Here's a link to the github repo as well!
If you need anymore information please do not hesitate to ask!
CcInput
...ANSWER
Answered 2021-May-17 at 23:45The bug is in the propsToPass
computed property, where it defaults type
to undefined
when valueType
is not "number"
:
QUESTION
I have created a button that eventually will have an onclick event-- when the user hovers over the button a div element pops up with an anchor that says "learn more" (in the example i used a long string to help solidify the issue) The code i designed works as expected with a mouse, however using the keyboard to tab across the elements -- the keyboard will first select the button (good) then will select the anchor (also good) but the anchor will immediately drop out of view since the parent isnt being hovered. This causes additional issues since it will maintain focus on the now hidden element and cause unexpected movements in content.
I have designed a codepen to demonstrate this issue https://codepen.io/honeynutz/pen/bGgXQyx
My code:
...ANSWER
Answered 2021-May-05 at 12:58Not sure if CSS can solve it for you this way but yeah below is a sample JS code that might work :-
QUESTION
It's long been common practice to remove outline via CSS outline: none;
from interactable elements such as buttons, since most of the time it looks off brand, but it hinders accessibility and makes navigating websites harder for people with disabilities that rely on keyboard navigation.
The problem is I have yet to find an easy way to differentiate the source of focus events between mouse/keyboard, and clicking as well as keyboard tabbing elements will trigger the focus state.
I know this issue has always been kind of a hot topic, but most sources are several years old, so I will show the main 4 methods I've found on how to achieve keyboard only focus, each with it's own pros and cons:
- The "cheating" method, some websites such as Target.com have the same styles for hovering and focusing, this design choice gave them the option of not needing to remove the focus outline at all.
Pros: Goes around the problem.
Cons: Limited in design options.
...ANSWER
Answered 2021-Apr-21 at 05:59Short answer: no, you have essentially listed your options here if you are aiming for "perfection" (where it works in all browsers exactly the same).
However all 4 of the options have drawbacks as you stated.
Personally I would go for a "best fit" solution, where some users may end up with focus indicators on click but most new browsers will handle things gracefully:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install focus-within
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page