Navigation Menu

Skip to content

Commit

Permalink
add focus state styles for keyboard navigation.
Browse files Browse the repository at this point in the history
  • Loading branch information
nisarhassan12 committed May 14, 2020
1 parent e5eb140 commit 1a8bfd9
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
32 changes: 29 additions & 3 deletions index.css
Expand Up @@ -192,6 +192,21 @@ a {
font-weight: 400;
font-family: 'Jost', sans-serif;
transition: all .2s;
outline: 2px solid transparent;
}

::-moz-focus-inner {
border: 0;
}

button:focus,
a:focus {
outline: 2px solid var(--pink);
}

body:not(.user-is-tabbing) button:focus,
body:not(.user-is-tabbing) a:focus {
outline: none;
}

.link:hover {
Expand All @@ -208,6 +223,10 @@ a {
font-weight: 400;
}

.btn:focus {
outline: none;
}

.btn::after {
content: '';
display: block;
Expand All @@ -221,7 +240,8 @@ a {
transition: all 0.2s cubic-bezier(1, 0.68, 0.16, 0.9);
}

.btn:hover::after {
.btn:hover::after,
.btn:focus::after {
right: 0;
background: var(--pink);
}
Expand All @@ -235,7 +255,8 @@ a {
display: none;
}

.btn--pink:hover {
.btn--pink:hover,
.btn--pink:focus {
background: transparent;
}

Expand All @@ -261,7 +282,12 @@ a {
transition: all 0.2s cubic-bezier(1, 0.68, 0.16, 0.9);
}

.link__text:hover::after {
.link__text:focus {
outline: none;
}

.link__text:hover::after,
.link__text:focus:after {
right: 0;
background: var(--pink);
}
Expand Down
2 changes: 1 addition & 1 deletion index.html
Expand Up @@ -2,7 +2,7 @@
Hello 馃槉.
This template is designed and developed by Nisar Hassan Naqvi
for anyone to use for free or customize the way they want.
for anyone to use for free or customize the way they like.
Github Repo: https://github.com/nisarhassan12/portfolio-template/
My Website: https://nisar.dev
Expand Down
23 changes: 23 additions & 0 deletions index.js
@@ -1,3 +1,26 @@
/* -----------------------------------------
Have focus outline only for keyboard users
---------------------------------------- */

const handleFirstTab = (e) => {
if(e.key === 'Tab') {
document.body.classList.add('user-is-tabbing')

window.removeEventListener('keydown', handleFirstTab)
window.addEventListener('mousedown', handleMouseDownOnce)
}

}

const handleMouseDownOnce = () => {
document.body.classList.remove('user-is-tabbing')

window.removeEventListener('mousedown', handleMouseDownOnce)
window.addEventListener('keydown', handleFirstTab)
}

window.addEventListener('keydown', handleFirstTab)

const backToTopButton = document.querySelector(".back-to-top");
let isBackToTopRendered = false;

Expand Down

0 comments on commit 1a8bfd9

Please sign in to comment.