Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

feat(Loader): add delay prop #969

Merged
merged 5 commits into from
Feb 27, 2019
Merged

feat(Loader): add delay prop #969

merged 5 commits into from
Feb 27, 2019

Conversation

layershifter
Copy link
Member

@layershifter layershifter commented Feb 26, 2019

Fixes #888. See #888 (comment).

/** A loader can contain an indicator. */
indicator?: ShorthandValue

/** Loaders can appear inline with content. */
inline?: boolean
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added missing prop definition

@codecov
Copy link

codecov bot commented Feb 26, 2019

Codecov Report

Merging #969 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #969      +/-   ##
==========================================
+ Coverage   80.74%   80.77%   +0.02%     
==========================================
  Files         665      665              
  Lines        8508     8521      +13     
  Branches     1499     1439      -60     
==========================================
+ Hits         6870     6883      +13     
  Misses       1624     1624              
  Partials       14       14
Impacted Files Coverage Δ
packages/react/src/components/Loader/Loader.tsx 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6ec2add...4a0c60e. Read the comment docs.

Copy link
Contributor

@johannao76 johannao76 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this!

label: customPropTypes.itemShorthand,
labelPosition: PropTypes.oneOf(['above', 'below', 'start', 'end']),
size: customPropTypes.size,
}

static defaultProps = {
accessibility: loaderBehavior,
delay: 0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be provide a more reasonable default? Maybe 100ms?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default it should 0 to keep existing behavior.


if (delay > 0) {
this.delayTimer = window.setTimeout(() => {
this.setState({ visible: true })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like we should clear the timeout here too and set this.delayTimer = null

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They will never collide because it's called in componentDidMount(), there are no obvious reasons to clear it.

}

componentWillUnmount() {
clearTimeout(this.delayTimer)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if this.delayTimer is not null/undefined before calling clearTimeout

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please clarify why need it?

Passing an invalid ID to clearTimeout() silently does nothing; no exception is thrown.

https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/clearTimeout#Notes

IE 11

image

Chrome

image

@mnajdova
Copy link
Contributor

LGTM, only thing is that maybe we should add test for this behavior?

import * as React from 'react'

const LoaderExampleDelay: React.FC<{ knobs: { mounted: boolean } }> = ({ knobs }) => (
<div style={{ minHeight: 24 }}>{knobs.mounted && <Loader delay={500} />}</div>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use here Flex with padding instead of div?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I don't think that it's a case for Flex. We require there minHeight because Loader will render null with delay, the same behavior as there: https://evergreen.segment.com/components/spinner/

Did I miss something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to avoid this effect:

loader-delay

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha, got it! Let's leave it as it is then..

@layershifter layershifter merged commit 64027e1 into master Feb 27, 2019
@layershifter layershifter deleted the feat/loader-delay branch February 27, 2019 10:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants