Skip to content

Commit

Permalink
enhance the anker even more and make it compatible with the button anker
Browse files Browse the repository at this point in the history
  • Loading branch information
tujoworker committed Jan 11, 2019
1 parent 14fecd4 commit d52f9e2
Show file tree
Hide file tree
Showing 18 changed files with 82 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Read more about the term Page Focus in the [Body Component](/uilib/components/bo
```html
<body>
<aside><!-- focusable navigation --></aside>
<main class="dnb-no-focus" tabindex="-1">
<main class="no-focus" tabindex="-1">
<!-- more markup with focusable HTMLElements -->
</main>
</body>
Expand Down
7 changes: 6 additions & 1 deletion packages/dnb-design-system-portal/src/shared/menu/Card.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,14 @@ const linkStyle = css`
background-color: var(--color-white);
transition: background-color 0.5s ease;
${'' /* transition: transform ease-out 0.5s;
transform: scale3d(1, 1, 1); */}
&:focus,
&:hover {
background-color: var(--color-mint-green-50);
${'' /* transform: scale3d(1.02, 1.02, 1);
transition: transform ease-out 0.3s; */}
}
`

Expand Down Expand Up @@ -142,7 +147,7 @@ export default class Card extends PureComponent {
>
<Link
css={[linkStyle, customStyle]}
className="no-dnb-style"
className="no-style"
to={url}
onClick={onClick}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const Content = ({ className, children }) => (
className={classnames(
'dnb-style',
'dnb-page-content',
'dnb-no-focus',
'no-focus',
className
)}
css={markdownStyle}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<details>
<summary className="dnb-fake-focus">Try to focus me</summary>
<summary className="fake-focus">Try to focus me</summary>
My main focus state has been removed and replaced by the helping class
.dnb-fake-focus.
.fake-focus.
</details>
<div className="dnb-sr-only">
I am only visible to screen readers, so you probably can't see me..
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,11 @@ exports[`Button scss have to match snapshot 1`] = `
border: none; }
.dnb-button[type='button'] {
appearance: none; }
a .dnb-button {
border-bottom: none; }
button.dnb-button::-moz-focus-inner .dnb-button {
border: none; }
a.dnb-button {
border-bottom: none;
transition: none; }
"
`;
11 changes: 6 additions & 5 deletions packages/dnb-ui-lib/src/components/button/style/_button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,14 @@
appearance: none;
}

// make sure we style a nodes like a button
@at-root a & {
border-bottom: none;
}

/* Firefox includes a hidden border which messes up button dimensions */
@at-root button#{&}::-moz-focus-inner & {
border: none;
}
}

// make sure we style an Anker like a button
a.dnb-button {
border-bottom: none;
transition: none;
}
Original file line number Diff line number Diff line change
Expand Up @@ -479,11 +479,13 @@ exports[`Dropdown scss have to match snapshot 1`] = `
border: none; }
.dnb-button[type='button'] {
appearance: none; }
a .dnb-button {
border-bottom: none; }
button.dnb-button::-moz-focus-inner .dnb-button {
border: none; }
a.dnb-button {
border-bottom: none;
transition: none; }
/*
* DNB FormLabel
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,13 @@ exports[`InputMasked scss have to match snapshot 1`] = `
border: none; }
.dnb-button[type='button'] {
appearance: none; }
a .dnb-button {
border-bottom: none; }
button.dnb-button::-moz-focus-inner .dnb-button {
border: none; }
a.dnb-button {
border-bottom: none;
transition: none; }
/*
* DNB FormLabel
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,11 +421,13 @@ exports[`Input scss have to match snapshot 1`] = `
border: none; }
.dnb-button[type='button'] {
appearance: none; }
a .dnb-button {
border-bottom: none; }
button.dnb-button::-moz-focus-inner .dnb-button {
border: none; }
a.dnb-button {
border-bottom: none;
transition: none; }
/*
* DNB FormLabel
*
Expand Down
2 changes: 1 addition & 1 deletion packages/dnb-ui-lib/src/components/modal/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ class ModalContent extends PureComponent {
aria-hidden="true"
aria-modal="true"
tabIndex="-1"
className="dnb-modal__content__inner dnb-no-focus dnb-style"
className="dnb-modal__content__inner no-focus dnb-style"
onClick={this.preventClick}
onKeyDown={this.onKeyDownHandler}
{...params}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ exports[`Modal component have to match snapshot 1`] = `
aria-hidden="true"
aria-labelledby={null}
aria-modal="true"
className="dnb-modal__content__inner dnb-no-focus dnb-style"
className="dnb-modal__content__inner no-focus dnb-style"
id={null}
onClick={[Function]}
onKeyDown={[Function]}
Expand Down Expand Up @@ -707,11 +707,13 @@ exports[`Modal scss have to match snapshot 1`] = `
border: none; }
.dnb-button[type='button'] {
appearance: none; }
a .dnb-button {
border-bottom: none; }
button.dnb-button::-moz-focus-inner .dnb-button {
border: none; }
a.dnb-button {
border-bottom: none;
transition: none; }
.dnb-modal {
font-family: var(--font-family-std, sans-serif);
font-size: 1rem;
Expand Down
2 changes: 1 addition & 1 deletion packages/dnb-ui-lib/src/components/tabs/Tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ export default class Tabs extends PureComponent {
return (
<div
role="tablist"
className="dnb-tabs__tabs__tablist dnb-tab-focus"
className="dnb-tabs__tabs__tablist tab-focus"
tabIndex="0"
onKeyUp={this.onKeyUpHandler}
onKeyDown={this.onKeyDownHandler}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ exports[`Tabs component have to match snapshot 1`] = `
>
<Tabs>
<div
className="dnb-tabs__tabs__tablist dnb-tab-focus"
className="dnb-tabs__tabs__tablist tab-focus"
onKeyDown={[Function]}
onKeyUp={[Function]}
role="tablist"
Expand Down
4 changes: 2 additions & 2 deletions packages/dnb-ui-lib/src/patterns/helper-classes/Example.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ class Example extends PureComponent {
<Fragment>
<div className="example-box">
<details>
<summary className="dnb-fake-focus">Try to focus me</summary>
<summary className="fake-focus">Try to focus me</summary>
My main focus state has been removed and replaced by the
helping class .dnb-fake-focus.
helping class .fake-focus.
</details>
<div className="dnb-sr-only">
I am only visible to screen readers, so you probably can't see
Expand Down
2 changes: 1 addition & 1 deletion packages/dnb-ui-lib/src/patterns/helper-classes/details.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
| Selector | Description |
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `dnb-fake-focus` | Removes default focus outline from a focusable element and adds a custom visual focus state when is focused |
| `fake-focus` | Removes default focus outline from a focusable element and adds a custom visual focus state when is focused |
| `dnb-sr-only` | Visually hides an element, but is still reachable by screen readers. `sr`=screen reade |
| `dnb-not-sr-only` | The opposite of `dnb-sr-only` |
| `dnb-unstyled-list` | Removes default styling for lists. Apply to the `ul` or `ol` elements" |
Expand Down
2 changes: 1 addition & 1 deletion packages/dnb-ui-lib/src/patterns/main-nav/MainNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export default class MainNav extends PureComponent {
<Search id="nav_search_mobile" />
</div>
<div
className="dnb-main-nav__links dnb-width-limit dnb-fake-focus"
className="dnb-main-nav__links dnb-width-limit fake-focus"
tabIndex="-1"
ref={this._innerRef}
>
Expand Down
9 changes: 3 additions & 6 deletions packages/dnb-ui-lib/src/shared/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@
export const pageFocus = (element = null) => {
try {
if (!element) {
element = document.querySelector('.dnb-no-focus')
element = document.querySelector('.no-focus')
}
if (element instanceof HTMLElement) {
if (!element.hasAttribute('tabindex')) {
element.setAttribute('tabindex', '-1')
}
if (
element.classList &&
!element.classList.contains('dnb-no-focus')
) {
element.classList.add('dnb-no-focus')
if (element.classList && !element.classList.contains('no-focus')) {
element.classList.add('no-focus')
}
element.focus()
}
Expand Down
47 changes: 35 additions & 12 deletions packages/dnb-ui-lib/src/style/core/dnb-core.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ body {
}

// Anker
@mixin hover-style() {
background-color: var(--color-mint-green-50);
border-bottom-width: 2px;
}
@mixin active-style() {
color: #fff;
background-color: var(--color-sea-green);
border-bottom: none;
}
@mixin focus-style() {
@include fakeFocus();
border-bottom: none;
}
a {
// make sure we have always `display: inline;` as inline-block is breaking the border-bottom
display: inline;
Expand Down Expand Up @@ -46,21 +59,16 @@ a {

&:active,
&:hover {
background-color: var(--color-mint-green-50);
border-bottom-width: 2px;
@include hover-style();

// margins are not needed as long as we go for "inline"
// margin-bottom: -0.1875em;
}
&:active {
color: #fff;
background-color: var(--color-sea-green);
border-bottom: none;
@include active-style();
}

&:focus {
@include fakeFocus();
border-bottom: none;
@include focus-style();
}

transition: background-color 0.2s ease;
Expand All @@ -72,6 +80,15 @@ a {
transform: translateY(-1px);
}
}
a.hover-style {
@include hover-style();
}
a.active-style {
@include active-style();
}
a.focus-style {
@include focus-style();
}
a.with-animation {
position: relative; // because of z-index and underline/hover sudo classes
z-index: 1; // because of focus handling
Expand Down Expand Up @@ -122,7 +139,7 @@ a.with-animation {
}
}
}
a.no-dnb-style {
a.no-style {
padding: 0;
margin: 0;
white-space: normal;
Expand All @@ -131,6 +148,7 @@ a.no-dnb-style {
&:active,
&:hover {
color: inherit;
background-color: none;
}

&::after {
Expand All @@ -149,6 +167,11 @@ a.no-underline {
}
}
a.no-hover {
&:active,
&:hover {
color: inherit;
background-color: none;
}
// bg
&::before {
content: none;
Expand All @@ -172,13 +195,13 @@ html[data-whatinput='mouse'] .dnb-style *:focus {
html[data-whatinput='keyboard'] .dnb-style *:not(a):not(div):focus {
@include fakeFocus();
}
.dnb-no-focus {
.no-focus {
outline: none;
}
.dnb-fake-focus {
.fake-focus {
@include fakeFocus();
}
.dnb-tab-focus {
.tab-focus {
outline: none;
&:focus {
@include fakeFocus('keyboard');
Expand Down

0 comments on commit d52f9e2

Please sign in to comment.