Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/smoothen #39

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
box-sizing: border-box;
}

*:focus {
outline: none;
}

.floating-focus-enabled :focus, .floating-focus-enabled .focus {
outline: dodgerblue solid 3px;
outline-offset: 4px;
Expand Down Expand Up @@ -70,22 +66,24 @@
border: 0;
}

label {
position: relative;
overflow: hidden;
}

.file-upload-label.focus {
input[type=text]:nth-of-type(2):focus,
input[type=text]:nth-of-type(2).focus {
outline-offset: 0;
outline-color: orange;
outline-width: 2px;
outline-style: dashed;
}

label {
position: relative;
overflow: hidden;
}

input[type="file"] {
position: absolute;
bottom: 200%;
right: 200%;
width: 1px;
height: 1px;
z-index: -1;
}

.input-warning-wrapper {
Expand All @@ -96,9 +94,11 @@
box-sizing: border-box;
transition: max-height .25s ease;
}

.input-warning-wrapper > p {
margin: 0;
}

.input-warning-wrapper.show {
max-height: 50px;
}
Expand Down
27 changes: 6 additions & 21 deletions src/floating-focus.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ export default class FloatingFocus {
}

this.floater.classList.add('visible');
this.floater.classList.add('helper');
this.floater.classList.add('moving');

const focusTargetAttribute = target.getAttribute('focus-target');
if (focusTargetAttribute) {
Expand All @@ -100,12 +98,10 @@ export default class FloatingFocus {
this.resolveTargetOutlineStyle(this.target, this.floater);
this.repositionElement(this.target, this.floater);

// Override default styles after styling the floater
this.target.classList.add('floating-focused');

this.handleFloaterMove();

clearTimeout(this.helperFadeTimeout);
this.helperFadeTimeout = setTimeout(() => this.floater.classList.remove('helper'), HELPER_FADE_TIME);
this.showHelper();
}

handleBlur() {
Expand Down Expand Up @@ -138,19 +134,10 @@ export default class FloatingFocus {
clearInterval(this.monitorElementPositionInterval);
}

handleFloaterMove() {
if (this.floaterIsMoving) {
return;
}

this.floaterIsMoving = true;

const removeMovingClass = () => {
this.floater.classList.remove('moving');
this.floater.removeEventListener('transitionend', removeMovingClass);
this.floaterIsMoving = false;
}
this.floater.addEventListener('transitionend', removeMovingClass.bind(this));
showHelper() {
this.floater.classList.add('helper');
clearTimeout(this.helperFadeTimeout);
this.helperFadeTimeout = setTimeout(() => this.floater.classList.remove('helper'), HELPER_FADE_TIME);
}

addPixels(pixels1, pixels2) {
Expand Down Expand Up @@ -218,9 +205,7 @@ export default class FloatingFocus {
return;
}

this.floater.classList.add('moving');
this.repositionElement(this.target, this.floater);
this.handleFloaterMove();
}

repositionElement(target, floater) {
Expand Down
8 changes: 3 additions & 5 deletions src/floating-focus.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@
overflow: hidden;
z-index: 9999999999; // It should always be on top of everything, no matter what.

&.moving {
transition-property: opacity, left, top, width, height, border-width, border-radius;
transition-duration: .2s, .1s, .1s, .1s, .1s, .1s, .1s;
transition-timing-function: linear, ease, ease, ease, ease, ease, ease;
}
transition-property: opacity, left, top, width, height, border-width, border-radius;
transition-duration: .2s, .1s, .1s, .1s, .1s, .1s, .1s;
transition-timing-function: linear, ease, ease, ease, ease, ease, ease;

&.enabled.visible {
opacity: 1;
Expand Down