ng-disabled on anchor inside <li> - html

How can I disable drop down menu item that uses ui-router and looks like this?
<ul class="dropdown-menu">
<li><a ui-sref="state.random">A random state</a></li>
</ul>
obviously this doesn't work:
<li ng-disabled="true"><a ui-sref="state.random">A random state</a></li>
nor this:
<li><a ui-sref="state.random" ng-disabled="true">A random state</a></li>

ng-disabled don't work on the li tag. Need to do this using css styles.
.disabled {
pointer-events:none; //This makes it not clickable
opacity:0.6; //This grays it out to look disabled
}
<li class="disabled"><a ui-sref="state.random">A random state</a></li>

Disabling might not work here. You may have to use a ternary operator with ui-sref. As I assume disabling would be conditional. The disabled style effect can be introduced with CSS.
$scope.someValue = false;
<li><a ui-sref={{someValue ? 'state.random' : ''}}>A random state</a></li>

I encountered a similar problem (angular 2), here is what worked for me:
HTML file:
<li (click)="onClick(item, $event)"
tooltip="{{isItemDisabled() ? getText(item.tooltipText) : undefined}}">
<a href="" role="tab" data-toggle="tab"
[ngClass]="{'disabled': isItemDisabled()}"
id="btnSelect{{getMenuLabel(tabitem)}}">{{getMenuLabel(tabitem)}}</a>
</li>
TS file:
onClick(isItemDisabled, $event) {
$event.preventDefault();
if (!isItemDisabled) {
// do whatever
}
}
CSS file:
disabled {
opacity: 0.6;
cursor: not-allowed;
pointer-events: none;
}

Related

Anchor tag disabled color attribute not working?

I did disabled anchor tag using component and need to show grey color as disabled link, but here the link is disabled, not turned into grey color. So user cant find whether it is disabled or not. could you please help me out?
HTML:
<li class="nav-item" [class.disabled]="profile_flag">
<a class="nav-link {{routeProfileStatus}}" style="cursor: pointer;" tabindex="
{{profile_flag?-1:0}}" (click)="gotoProfile()">My Profile</a>
</li>
<li class="nav-item" [class.disabled]="waitingRoom_flag">
<a class="nav-link {{routeStatus}}" style="cursor: pointer;" tabindex="
{{waitingRoom_flag?-1:0}}" (click)="gotoDashboard()">Waiting Room</a>
</li>
component:
profile_flag : boolean = false;
waitingRoom_flag : boolean = false;
css:
.disabled{
color:grey;
text-decoration:none;
cursor:default;
pointer-events:none;
}
Your .disabled class is added to the li tag, but you need to apply that rule to the a inside li,
So use .disabled > a instead as a selector for that CSS rule.
Remove [class.disabled] from li and use ngClass on top of a
<a class="nav-link {{routeStatus}}" [ngClass]="{ 'disabled' : waitingRoom_flag}" style="cursor: pointer;" tabindex="{{waitingRoom_flag?-1:0}}" (click)="gotoDashboard()">Waiting Room</a>
You need to use the disabled class in the a tag instead of the li tag

routerLink selected option color

I need to have red color on selected link About
<nav>
<a routerLink="" routerLinkActive="active" [routerLinkActiveOptions]="{exact:true}">About</a>
<a routerLink="product" routerLinkActive="active">Employees</a>
</nav>
How can I do that?
The routerLinkActiveattribute receive a css class. In your case, active is the css class.
So you will just need to declare the class in this way in your css file:
.active{
color:red;
}

Background image present but not visible

On the following site http://haircolourideas.eu/#section2 I have a ul in the services section and the li's have background images . The li's have classes of service1 , service2 etc. The background images have suddenly become invisible . If I inspect element the css is correct and it shows that the images are present . The site has been live a couple of months and without me changing anything this has just happened today
<ul id="services-list" class="hidden">
<li class="service1 service-img"><label class="btn" for="modal-1"><h3>meche</h3></label></li>
<li class="service2 service-img"><label class="btn" for="modal-2"><h3>tinting</h3></label></li>
<li class="service3 service-img"><label class="btn" for="modal-3"><h3>fashion</h3></label></li>
<li class="service4 service-img"><label class="btn" for="modal-4"><h3>change</h3></label></li>
</ul>
.service1 {
background: url(../img/meche1.png);
cursor: pointer;
}
.service2 {
background: url(../img/tint1.png);
cursor: pointer;
}
.service3 {
background: url(../img/fashion1.png);
cursor: pointer;
}
.service4 {
background: url(../img/change1.png);
cursor: pointer;
}
Remove class hidden from thoes nodes:
<div id="services-info" class="hidden">
<ul id="services-list" class="hidden">
<ul id="services-list" class="hidden">
<li class="service1 service-img"><label class="btn" for="modal-1"><h3>meche</h3></label></li>
<li class="service2 service-img"><label class="btn" for="modal-2"><h3>tinting</h3></label></li>
<li class="service3 service-img"><label class="btn" for="modal-3"><h3>fashion</h3></label></li>
<li class="service4 service-img"><label class="btn" for="modal-4"><h3>change</h3></label></li>
Remove the class="hidden" from your ul
The problem is that the animation doesn't function because in the ul you have class="hidden" which makes opacity: 0 that hides all the ul section. The class="hidden" is applied because you are missing this script in your server jquery.viewportchecker.js. If you open your console with inspect element you can see the error. The script makes the class hidden apply or not based on the section you are. In some way the script got deleted from your server as you can see in the link: http://haircolourideas.eu/js/jquery.viewportchecker.js so you had to put it back and with that also this jquery error:
"Uncaught TypeError: jQuery(...).addClass(...).viewportChecker is not a function"
in you console will disappear and the website will function as before
You can try this: i can say surely show your image.
.hidden {
/* opacity: 0; */
}
If don't need then remove opacity:0 property, otherwise set
opacity: 1;
Otherwise You can remove hidden class from ul
Just remove the class hidden means
<ul id="services-list" class="hidden"> not visible
<ul id="services-list" class=""> visible

:active selector for custom li tag bullets

I have the following problem:
I have a ul with blue list item text and a blue custom bullet. Now if the user clicks a li the text should be black and the custom bullet as well.
The text is easy to change, but i don't know how i could do it, that the custom bullet also stays black.
When the user hovers trough the menu the custom bullets and the text turns black. This is already working. But if the user is on a page, as soon he leaves the hover area the bullets turn blue again. This shoud not be the case.
Here is what i have already:
<ul class="listMenuItem--s">
<li class="listMenuChild">
Dienstleistungen
<ul class="sub-nav">
<li>Treuhand & Finanzen </li>
<li>Wirtschaftsprüfung</li>
<li>Unternehmensberatung / Nachfolge</li>
<li>Pensionierungs-, Vorsorge- und Steuerplanung</li>
<li>Informatik</li>
</ul>
</li>
<li class="listMenuChild">
Über uns
</li>
<li class="listMenuChild">
Publikationen
</li>
<li class="listMenuChild">
Hilfsmittel
</li>
<li class="listMenuChild">
Kontakt / Lageplan </li>
</ul>
And here the CSS.
.listMenuChild {
list-style-image: url("../img/bg_li.png");
margin-top: 5%;
}
.listMenuChild:active {
list-style-image: url("../img/bg_li_h.png");
}
.listMenuChild:hover {
list-style-image: url("../img/bg_li_h.png");
}
Is it because :active and :hover don't work together?
Any help much appreciated
:active means "While being clicked on or otherwise activated" (e.g. a focusable element would also be activated while you press the Enter key when it has a focus). Note while, not after.
It doesn't seem to have any effect for you because you never activated it without also hovering it (and your hover rule comes after the active rule).
It sounds like when you say "When the list item is active" you mean "When the link inside the list item has an href attribute that resolves to the URL of the current page". That isn't something you can express with CSS.
Use server side code to add a class to the list item based on the page you are loading and target that class with CSS.
If you have an :active class on a non-focussable item like <li>, it works only during mousedown. If you need to make it work without :hover, make it focussable using tabindex.
<li class="listMenuChild" tabindex="0">
The above code is only for it to stay. i.e., Currently the browser applies :active for only mousedown event. So that occurs only when you are having both :hover:active pseudo class:
.listMenuChild:hover:active {backgkround: #999;}
As you are using pages for each item you could create another class, add it to the list item for each page where that list item is to be highlighted for that page:
.listMenuChild {
list-style-image: url("../img/bg_li.png");
margin-top: 5%;
}
.listMenuChildActive {
list-style-image: url("../img/bg_li_h.png");
}
.listMenuChild:hover {
list-style-image: url("../img/bg_li_h.png");
}
HTML example:
<ul class="listMenuItem--s">
<li class="listMenuChildActive">
Dienstleistungen
<ul class="sub-nav">
<li>Treuhand & Finanzen </li>
<li>Wirtschaftsprüfung</li>
<li>Unternehmensberatung / Nachfolge</li>
<li>Pensionierungs-, Vorsorge- und Steuerplanung</li>
<li>Informatik</li>
</ul>
</li>
<li class="listMenuChild">
Über uns
</li>
<li class="listMenuChild">
Publikationen
</li>
<li class="listMenuChild">
Hilfsmittel
</li>
<li class="listMenuChild">
Kontakt / Lageplan </li>
</ul>
Try swapping these two lines:
.listMenuChild:hover {
list-style-image: url("../img/bg_li_h.png");
}
.listMenuChild:active {
list-style-image: url("../img/bg_li_h.png");
}
Remember this mnemonic phrase:
LoVe and H Ate
The 4 pseudo-selectors:
a:link // **L**ove
a:visited // Lo**V**e
a:hover // **H**ate
a:active // H**A**te
If they are not in that specific order, they probably will not work correctly.
https://css-tricks.com/remember-selectors-with-love-and-hate/

Disable a link in Bootstrap

The first example didn't work. I need to have always a list to disable links? Or what is wrong with my first demo?
<a class="disabled" href="#">Disabled link</a>
<ul class="nav nav-pills">
...
<li role="presentation" class="disabled">Disabled link</li>
...
</ul>
https://jsfiddle.net/7y0u2amy/
I think you need the btn class.
It would be like this:
<a class="btn disabled" href="#">Disabled link</a>
It seems that Bootstrap doesn't support disabled links. Instead of trying to add a Bootstrap class, you could add a class by your own and add some styling to it, just like this:
a.disabled {
/* Make the disabled links grayish*/
color: gray;
/* And disable the pointer events */
pointer-events: none;
}
<!-- Make the disabled links unfocusable as well -->
Link to disable<br/>
Non-disabled Link
I just created my own version using CSS. As I need to disabled, then when document is ready use jQuery to make active. So that way a user cannot click on a button until after the document is ready. So i can substitute with AJAX instead. The way I came up with, was to add a class to the anchor tag itself and remove the class when document is ready. Could re-purpose this for your needs.
CSS:
a.disabled{
pointer-events: none;
cursor: default;
}
HTML:
<a class="btn btn-info disabled">Link Text</a>
JS:
$(function(){
$('a.disabled').on('click',function(event){
event.preventDefault();
}).removeClass('disabled');
});
If what you're trying to do is disable an a link, there is no option to do this. I think you can find an answer that will work for you in this question here.
One option here is to use
123n
Disabled href tag
You cant set links to "disabled" just system elements like input, textfield etc.
But you can disable links with jQuery/JavaScript
$('.disabled').click(function(e){
e.preventDefault();
});
Just wrap the above code in whatever event you want to disable the links.
I just removed 'href' attribute from that anchor tag which I want to disable
$('#idOfAnchorTag').removeAttr('href');
$('#idOfAnchorTag').attr('class', $('#idOfAnchorTag').attr('class')+ ' disabled');
Thanks for #jacob-van-lingen's comment, You can extend .btn-link in your global style
a.disabled{
#extend .btn-link
}
I developed the following solution because when I apply class styles such as btn disabled offered by Bootstrap 5 to an <a> element inside a card, margin and padding are applied to the element:
.disabled {
color: currentColor;
cursor: not-allowed;
opacity: 0.5;
text-decoration: none;
}
Disabled Link
I liked the answer by Sercan and I added a tiny jQuery to it, so that the links are also not followed on click:
$(document)
.on("click",
"a.disabled",
function () {
return false;
});
and for the look from the Answer above:
.disabled {
color: currentColor;
cursor: not-allowed;
opacity: 0.5;
text-decoration: none;
}