CSS3 switch inside clickable element - html

I have the following html:
<li class="list-group-item li-tab-1">
<div class="list-group-item-desc" data-target="#tab-1" data-toggle="tab">
<strong>1</strong>
<div class="small m-t-xs">
<p>Description</p>
</div>
<div class="onoffswitch">
<input type="checkbox" checked="checked" class="onoffswitch-checkbox" id="tab-1-enabled" /> <label class="onoffswitch-label" for="tab-1-enabled"> <span
class="onoffswitch-inner"></span> <span class="onoffswitch-switch"></span>
</label>
</div>
</div>
</li>
This is a Bootstrap tab. .onoffswitch is a CSS3 switch.
I'm trying to make the entire <li> clickable to show #tab-1 as the tab content. I can do this by defining a <div> with the data-target and data-toggle attributes. This works - when I click the div the tab shows.
However, embedded inside the <li> is a CSS3 switch. I want that to work independently of the clickable div.
This is similar to Links inside of larger clickable areas (CSS Only), except the nested clickable elements are CSS3 switches instead of anchors.
Using the CSS3 switch outside the anchor works fine.
I tried making the actual hidden checkbox visible, removing the CSS3 styling, and clicking that. That does work, so is this related to CSS3?
I wondered if this is related to propogation - the trouble is that if I set an event listener for control.select or change I get no events - just the div click event.

Turned out it was propogation that was the problem (thanks #TW80000).
$(".list-group-item-desc").click(function(ev) {
var isSwitchClick = $('.onoffswitch').has($(ev.target)).length > 0;
if(isSwitchClick) {
ev.stopPropagation();
}
});
That checks whether the click was inside the switch, and if so stops propogation.
In reality I have since moved the Bootstrap tab attrributes into the <li> but I think either approach should work to avoid swallowing the event.

Related

Why doesn't :hover work to effect on other objects?

I'm new in HTML and CSS. In fact, it's my first site I build in my learning. Why doesn't :hover effect work on the class I've pointed it to?
I'd be really thankful for every help. But please explain, don't just show me "how to".
I'm trying to get the search_type selector getting visible only after hoovering the "search" button
Thanks in advance. (Here's the edited to be simpler code)
https://codepen.io/_Hiderr/pen/WNNdJdo
Like so: https://codepen.io/bjorniobennett/pen/OJJzZrX?editors=1100
The basic behaviour of :hover is that it can affect itself and the elements inside of it, or the next adjacent sibling . So I wrapped the search button and the select element in it's own container, and placed the :hover on the container itself. By placing the :hover on the container, you can now manipulate it's children.
<div class="search-container">
<select class="search selector" name="search_type">
<option value="">Videos</option>
<option value="search_users">Channels</option>
</select>
<input class="search button" type="submit" value="Search" />
</div>
Seems that your css selector has no match in the markup:
search.button:hover ~ .search.selector
would match any element like this:
<button class="search button">Search</button> <span class="search selector">Selected</span>
See: https://codepen.io/andreaslangsays/pen/RwwxyEN

How to set up tabindex to a button inside of list item?

I am creating a custom Typeahead component and trying to make sure that the Typeahead's popup is accessible through keyboard navigation. This it my HTML markup:
<div class="wrapper">
<input type="text" ...>
<div class="data-wrapper" tabindex="-1">
<ul>
<li>
<button tabindex="0">John Doe</button>
</li>
<li>
<button tabindex="0">Mary Poppins</button>
</li>
</ul>
</div>
</div>
I am not able to tab into buttons (when I click TAB, I go back to the address bar when only this markup is present). However, if I add tabindex property to <li> elements, I am able to tab into the list items. However, I am not able to click the buttons because keyboard is focused on the list item. How am I supposed to set up focus for the buttons to be navigable using keyboard?
EDIT: Or better yet, is it possible to change the behavior of the typeahead; so that, it is navigable using arrow keys (like select boxes).

Open a link and active a checkbox

Im trying to create an element, which when clicked, both opens a hyperlink and actives a label connected to a checkbox. The element is a menu item. When that menu item is clicked, I want the anchor/link to be opened and the menu to be closed through CSS, hence the checkbox.
However, whenever I put the label inside the hyperlink, the checkbox gets checked, but the hyperlink does not get opened.
<a href="#anchor">
<label for="checkbox">
Menu Item
</label>
</a>
When I put the hyperlink inside the label, the opposite happens: the link gets opened, but the checkbox does not get checked.
<label for="checkbox">
<a href="#anchor">
Menu Item
</a>
</label>
Is it possible to active the label and open the hyperlink simultaneously without using JavaScript? If so, how?
Remove the a element! It's not valid to have a label inside an anchor or an anchor inside a label.
Just add the onclick="location.hash=''" event for your input element to run code. (an example below)
<input type="checkbox" id="checkbox" onclick="location.hash='#anchor';" />
<label for="checkbox">Menu Item</label>
<!-- div for margin -->
<div style="height:10000px"></div>
<a name="anchor">Lorem ipsum dolor sit amet.</a>

Accessing hidden input elements

My question:
How to access hidden input elements via tab?
Detailed explanation:
On my website, for radio buttons I have set visibility none and customized the before element to get a custom design.
The problem is when I try to access the input type radio via tab I am unable to do it since it is visibility hidden.
So, can anyone suggest me how to access hidden input elements with tab?
Website
Demo Form
Please visit the link above, you will find a form there. Now, please try to access the radio buttons with tab. It skips the radio buttons.
You have to have an item in your tab flow that supports tabindex, and since your radio button is hidden that won't work. The anchor tag does support tab index however, so you can wrap the inner elements of each of your li tags with an a tag, and assign it a tabindex that works in your flow...
Change:
<li tabindex="0" class="radio gchoice_2_14_0">
<input style="margin-left:1px;" name="input_14" type="radio" value="2017/2018" id="choice_2_14_0" onclick="gf_apply_rules(2,[0]);" onkeypress="gf_apply_rules(2,[0]);">
<label tabindex="0" for="choice_2_14_0" id="label_2_14_0">2017/2018
</label>
</li>
To:
<li tabindex="0" class="radio gchoice_2_14_0">
<a tabindex="1010">
<input style="margin-left:1px;" name="input_14" type="radio" value="2017/2018" id="choice_2_14_0" onclick="gf_apply_rules(2,[0]);" onkeypress="gf_apply_rules(2,[0]);">
<label tabindex="0" for="choice_2_14_0" id="label_2_14_0">2017/2018
</label>
</a>
</li>
This will give the anchor tag focus when you tab to it (assuming the previous element's tabindex is '1009' or lower).
This answers your question on how to tab to it. Now that you have that, you'll need to do a couple things:
Style the element's css for form li.radio a:focus as you see fit.
Set up key press events for the a elements so that you can actually select your fake radio button with the enter key press when it's focused.

Show DIV on startup of page, hide when click on any radio button

So, I decided to make page where all content is in hidden DIV. Basicly page start blank without any content. After clicking on radio-buttons it show one DIV, and hide another.
This is buttun named "Button_name" that will open "opt3" div's content.
<input id="tab-3" type="radio" name="radio-set" class="tab-selector-3" value="opt3"/>
<label for="tab-3" class="tab-label-3"> BUTTON_NAME </label>
After clicking this will open "opt3" div:
<div id="opt3" class="desc" style="display: none;">
content of div
</div>
And now:
How to make some text appear in new DIV when page is opened (or refreshed by F5), but closed directly after clicked any button in menu options?
EDIT:
Script for buttons
$(document).ready(function(){
$("input[name=radio-set]").change(function() {
var test = $(this).val();
$(".desc").hide();
$("#"+test).show();
});
});
OK I figure it out in easiest way, I think!
If someone want same effect as me - you just have to put in main div (where any other div will show after clicking on menu buttons) normal "opt" div, but without display:none.
<div id="opt20" class="desc" >
Ble ble 20
</div>
This will show "ble ble 20" only when page start, and after clicking on any menu button will hide away. Be sure that in future, you will not use again "opt20" button, because it will show you your start content.
There are tons of tutorials and info on jQuery. It really takes playing with it and studying the different options it has. Here is a quick sample of what you can do. Not exactly what you might need, but it might give you a start. jQuery is quite powerful. You will have to include the jQuery library js file in your code. http://jquery.com/
Some HTML
<input id="tab-3" type="radio" name="radio-set" class="tab-selector-3" value="opt3"/> Check me
<br /><input id="btn1" type="button" value="Click Me">
<div id="opt3" class="desc" style="display: none;">
I'm opt3 hidden from the start
</div>
<div id="otherdiv" class="desc" style="display: none;">
some other div that is shown when opt3 is clicked
</div>
and the jQuery
$(document).ready(function(){
$("#btn1").click(function(){
$("#opt3").show();
if($("#otherdiv").is(':visible')){
$("#otherdiv").hide();
}
});
$("#tab-3").change(function(){
$("#otherdiv").show();
if($("#opt3").is(':visible')){
$("#opt3").hide();
}
});
});
See it in action http://jsfiddle.net/8fUXW/1/
BTW Google specific things you need then piece them together instead of trying to find an exact solution. That would be pretty difficult.