Tab-Index for absolutely positioned elements in layout - html

Tab Index for Absolute-Position Elements
For the time being, lets assume I wrote the code below:
<header class="header hap" [ngClass]="authority">
<div class="header-inner">
<div class="header-identity">
<a id="theLogo" class="logo" [routerLink]="[links.home]" title="Navigate to Home">
<img src="assets/logo-white.svg" alt="Logo">
</a>
<span class="client-logo" *ngIf="user.brandingImage && !user.isTheAdmin()">
<img class="brandingImage" [src]="user.brandingImage" [alt]="user.brandingName" onerror="this.style.display='none'">
</span>
[ more links ]
</div>
<nav class="main-nav for authenticated" [ngClass]="{'active':showMenu, 'app-only':!isCurrPageAdminApp()}">
<button class="menu" (click)="toggleMenu()">Menu</button>
<div class="main-nav-flyout" *ngIf="showMenu">
<div class="nav-header">
<ul>
<li>
<a id="main-nav-profile" [routerLink]="['/profile']"><span class="icon icon-user2"></span> My Profile</a>
</li>
[ more dropdown items ]
</ul>
<a id="main-nav-close" class="close"(click)="onClickMenuClose()"><span class="icon-cross"></span></a>
</div>
<div class="nav-body">
<ul *ngIf="isCurrPageAdminApp()" class="main-nav-list">
<li class="current-app">Administrative Tools</li>
<li><a id="main-nav-xAdmin" *ngIf="user.isTheAdmin()" [routerLink]="['admin/x']">X Admin</a></li>
[ more links ]
<li>
<span>Reports</span>
<ul>
<li class="user-status"><a id="main-nav-userStatusReport" [routerLink]="['admin/reports/userStatus']">User Status</a></li>
[ more links ]
</ul>
</li>
</ul>
<ul class="app-list" *ngIf="user.userApplications">
<li *ngIf="showTheLink()">
<a id="app-list-type" [routerLink]="['/']">
...
</a>
</li>
[ more links ]
<li *ngFor="let application of user?.userApplications">
<a id="app-list-{{application.abbreviation}}" *ngIf="!isAdminApp(application)" (click)="onClickMenuItem(application)">
{{ application.title }}
</a>
</li>
</ul>
</div>
</div>
</nav>
<nav class="user-nav for authenticated" role="menu">
<span *ngIf="user.brandingName" class="user-location">{{user.brandingName}}</span>
<span *ngIf="user.brandingName" class="pipe">|</span>
<a id="user-nav-profile" class="user-name" [routerLink]="['/profile']">
<span class="name">{{user?.firstName}} {{user?.lastName}}</span>
</a>
<a id="user-nav-logout" class="logout" [routerLink]="['/', 'logout']">Log out</a>
</nav>
</div>
</header>
Issue
Various elements -- probably .header-inner > * -- are styled using position: absolute;, so the tabindex-order is skewed for elements which are declared later in the markup but positioned geometrically earlier in the layout.
Question
Is there a way to force the tabindex to be, say, all natural indices (0) except for 2 items that need to be switched -- in a scalable way while not having to implement tabindex for every new item in the layout?

The short answer is no, it's not possible to switch only two elements without at least adding tabindex to every element in the flow that has to be focused before those two elements.
All elements with positive tabindex will be focused first in an incremental way, or in their source order if they have the same value, and all elements with default value or zero will be focused last.
So if you have 6 focusable elements and you want to have elements 5 and 6 to be focused after elements 1 and 2, you need something like this:
<input type="text" tabindex="1">1</input>
<input type="text" tabindex="1">2</input>
<input type="text">3</input>
<input type="text">4</input>
<input type="text" tabindex="1">5</input>
<input type="text" tabindex="1">6</input>
In general having the source order match the flow is the easiest way to make it work.
There is one particular case that is simpler. If the elements you want to move happen to be the first elements that need focus on your page, then in that particular case you can put the tabindex only on those elements.
For instance, if we wanted elements 5 and 6 be the first elements on the page, and everything else after them, all you need to do is this:
<input type="text">1</input>
<input type="text">2</input>
<input type="text">3</input>
<input type="text">4</input>
<input type="text" tabindex="1">5</input>
<input type="text" tabindex="1">6</input>
So in general, if the elements you want to change order are in the header, and they are the first things that should be focusable on your page, it should be easy to rearrange them and let the rest of the page flow naturally.
If the elements had to be last you are out of luck, you should either:
Put them last in the markup so they flow naturally
Remove them from the flow with tabindex=-1 and let the user focus manually

Related

Confused about the nature of Parent-child relationship in HTML

<header class="header header-home main-grid">
<div class="header-content">
<a class="logo-link" href="index.html">
<img src="logo.svg" alt="" class="logo">
</a>
<button aria-label="Open navigation" class="open-nav">☰</button>
<nav class="nav">
<button aria-label="Close navigation" class="close-nav">×</button>
<ul class="nav-list">
<li class="nav-item">
home
</li>
<li class="nav-item">
about us
</li>
<li class="nav-item">
contact
</li>
</ul>
</nav>
</div>
</header>
in this HTML - the main grid is on the header - than he creates another div header-content to hold the logo and navbar.
What I dont understand is how the children of header-content are still affected by the header parents main-grid.
Basically the way I'm reading this is that the div is a child to the header, and i thought that flexbox/grid only affected its direct children.
If the main-grid class is on the header - why is it still affecting the content of the div even though the content isnt a direct child to the main-grid?
Each parent will affect all of his children and all of his children's children, etc. In another word, if you know about inheritance, all of the nodes in HTML are inheriting the features of their parents by default.
You can overwrite a style or behavior of a child by specifying that in its own definition. For example, if the background of a parent is black, all of its children will have a black background unless you mention background-color:'white' in the definition of a child node.

<span> not starting where it starts where I want it to on new line

In the image you can see that if the title of the sidebar link is too long it goes to the next line. However it starts where the icon is located and not where the start of the span is. How would I style the class "side-nav-item" to where it will format where Administrator when it is shifted to the new line it starts where Give is.
<li class="side-nav-item">
<a data-bs-toggle="collapse" href="#userAccess" aria-expanded="false" aria-controls="userAccess"
class="side-nav-link">
<i class="uil-layer-group"></i>
<span>User Access</span>
<span class="menu-arrow"></span>
</a>
<div class="collapse" id="userAccess" data-bs-parent="#accordion">
<ul>
<li class="side-nav-item">
<a href="/task/add-location-access" class="side-nav-link">
<i class="uil-shield-check"></i>
<span> Give user access - Administrator</span>
</a>
</li>
<li class="side-nav-item">
<a href="/task/remove-location-access" class="side-nav-link">
<i class="uil-shield-slash"></i>
<span> Remove</span>
</a>
</li>
</ul>
</div>
</li>
Style <span> inside <a></a> as an inline-block. The behaviour you are seeing is expected from inline elements like <span> and <i>. Checkout concepts of inline elements, block elements and 'display' property in CSS. I am assuming you are new to HTML and CSS, so I suggest you begin with a good hands on video tutorial.
try this ,
<span
style="width:400px;text-align:start;height:max-content;"
>
Give user access - Administrator
</span>

CSS float inside the list avoid unwanted padding

In my list element I want to place the control buttons aside, from the left of the list item text. In order to do that I use a property float: left;, it does the job, but when there are more than one line in a list, every new line has a padding of a size of the previous floating block:
The list is based on Vue.js & Bootstrap.
My CSS/HTML code:
<ul class="items">
<transition-group name="item">
<li v-for="item in items" :key="item.id" mode="out-in">
<span>
{{item.properties.NAME}}
</span>
<span style="float: left;">
<span class="fa fa-wrench"></span>Update
<span class="fa fa-trash-o"></span>Delete
</span>
</li>
</transition-group>
</ul>
How to display buttons inside the list on the right/left side of the list just one under the other?
The final result should be something like that:
Item #1_____________________________________Update___Delete
Item #2_____________________________________Update___Delete
Your issue should be solved by resetting or clearing the float that you’ve created. As you’re using bootstrap you can simply add the class clearfix to your li element that you have added float to. This will add a pseudo after element which will reset the flat after the element.
The final code snippet:
<ul class="items">
<transition-group name="item">
<li v-for="item in items" :key="item.id" mode="out-in" style="padding-bottom:10px;" clearfix>
{{item.properties.NAME}}
<span style="float: left;">
<span class="fa fa-wrench"></span>עדכן
<span class="fa fa-trash-o"></span>מחק
</span>
</li>
</transition-group>
</ul>
Try style="clear:left;". If that doesn't work, you would actually do the float or the clear left on the 'li' element, not on the span containing the buttons. This way each 'li' containing the buttons will contain the buttons themselves.
Try something to this affect below. Since there is not a JS Fiddle, editing code for what your needs are harder to edit.
<ul class="items">
<transition-group name="item">
<li v-for="item in items" :key="item.id" mode="out-in" style="float:left; clear:left; width:100%; display:block">
<span>
{{item.properties.NAME}}
</span>
<span>
<a href="#" class="btn btn-success btn-xs" #click="edit_item(item)">
<span class="fa fa-wrench"></span>Update</a>
<span class="fa fa-trash-o"></span>Delete
</span>
</li>
</transition-group>
</ul>
Kind of like this. Quick and dirty. Except on the elements, instead of inline styling, highly recommend CSS.
https://jsfiddle.net/y1x53zx2/1/

element with tabindex 0 to next element with tabindex 1+ is not focused

I am having a HTML template with set of <a> tags. Added tabindex for the elements.
Issue is on clicking tab button to focus, element with tabindex 1+ is not focusing.
Requirement is focus should happen on changing the focus from element with tabindex 0 to an element with tabindex 1+.
<div>
<ul class="gn-filter-anchor-list">
<li>
<a title="Under $25.00" tabindex="0" href="/"><span class="off-screen">from Price</span> Under $25.00</a></li>
<li>
<a title="$25.00-$49.00" tabindex="0" href="/"><span class="off-screen">from Price</span> $25.00-$49.00</a></li>
<li>
<a title="$50.00-$74.00" tabindex="0" href="/"><span class="off-screen">from Price</span> $50.00-$74.00</a></li>
<li>
<a title="$75.00-$99.00" tabindex="0" href="/"><span class="off-screen">from Price</span> $75.00-$99.00</a></li>
<li>
<a title="Over $100.00" tabindex="0" href="/"><span class="off-screen">from Price</span> Over $100.00</a></li>
</ul>
</div>
<div >
<div class="dept-large">xxx</div>
<div class="dept-large">xxx</div>
<div class="dept-large">xxx</div>
</div>
<div >
<ul class="pagination" >
<li class="current"><a href="#" >1</a></li>
<li class="odd first"><a href="#" >2</a></li>
<li class="even"><a href="#" >3</a></li>
<li class="odd"><a href="#" >4</a></li>
</ul>
</div>
https://jsfiddle.net/sameer_ngl/mjps7ufs/
See below:
The tabindex global attribute is an integer indicating if the element can take input focus (is focusable), if it should participate to sequential keyboard navigation, and if so, at what position. It can take several values:
a negative value means that the element should be focusable, but
should not be reachable via sequential keyboard navigation;
0 means that the element should be focusable and reachable via
sequential keyboard navigation, but its relative order is defined
by the platform convention;
a positive value means should be focusable and reachable via
sequential keyboard navigation; its relative order is defined by
the value of the attribute: the sequential follow the increasing
number of the tabindex. If several elements share the same
tabindex, their relative order follows their relative position in
the document.
An element with a 0 value, an invalid value, or no tabindex value should be placed after elements with a positive tabindex in the sequential keyboard navigation order.
Source: https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex

Put div and input in same line inside link

I have this link in list with some inputs inside:
<ul class="code__list">
<li class="code__item"> <a class="code__link private" href="#">Test1<b><input type="text" class="intercomInput forCode" name="clientCode" value="1234"></b><div>Test2</div></a>
</li>
</ul>
How to place it in one row?
Fiddle
Replace your div with a span, or set the CSS display property to inline or inline-block as below.
<ul class="code__list">
<li class="code__item">
<a class="code__link private" href="#">Test1
<b>
<input type="text" class="intercomInput forCode" name="clientCode" value="1234">
</b>
<div style="display: inline-block">Test2</div>
</a>
</li>
</ul>
Instead of using div you can use span, because div is block element and span is inline, this is why your content is not showing in one line.
Try this:
<ul class="code__list">
<li class="code__item"> <a class="code__link private" href="#">Test1<b><input type="text" class="intercomInput forCode" name="clientCode" value="1234"></b><span>Test2</span></a>
</li>
</ul>
Updated Demo