components APIs
- Header
- Button
- Layout
- Footer
- Text
- Box
- Card
- Table
- Loading
- Select
- Loader
- Toolbar
- Icon
- CodeInput
- BottomSheet
- InfoBlock
- LanguageToggle
- ProgressCircles
- Ripple
- Toggle
- Tag
- Input
- Paginator
- Filter
- AsyncSelect
- CatalogBigButton
- ReadMore
- ConditionalWrapper
- LastCheckedDisplay
- PriceLabel
- PageTitle
- CartTable
- CartFinalPriceTable
- LoadingSpin
- InfoModal
- ProductCard
- RecommendCoupon
- PriceVales
- NomalLayout
- Web3ReactManager
- Popups
- CurrencyInput
- TransactionErrorContent
- TransactionConfirmationModal
- ConfirmationModalContent
- DoubleCurrencyLogo
- CustomModal
- CurrencySearchModal
- CurrencyLogo
- NumericalInput
- Logo
- QuestionHelper
- ListLogo
- DataTable
- WalletModal
- CustomTable
- MinimalPositionCard
- RemoveLiquidityModal
- CustomTooltip
- ColoredSlider
- ToggleSwitch
- FormattedPriceImpact
- SettingsModal
- ConfirmSwapModal
- AdvancedSwapDetails
- AddressInput
- LineChart
- StakeSyrupModal
- AccountDetails
- BetaWarningBanner
- AreaChart
- ChartType
- TokensTable
- PairTable
- TopMovers
- BarChart
- TransactionsTable
- StakeQuickModal
- UnstakeQuickModal
- SyrupCard
- CustomMenu
- SearchInput
- CustomSwitch
- FarmCard
- BuyFiatModal
- MoonpayModal
- RewardSlider
- Swap
- AddLiquidity
- PoolFinderModal
- PoolPositionCard
- SwapTokenDetails
- SuperHeader
- GlobalStyles
- PrimaryButton
- SectionTitle
- Section
- AccentSection
- ChainSelection
- CoinSelection
- AddressSelection
- SendAction
- Buttons
- Content
- Particles
- IconButton
- NotSupported
- InputSearch
- RouteGuard
- SearchBar
- FileInput
- GovBanner
- AuthForm
- DomainDetails
- Subnav
- ColumnFilter
- ImportExport
- selectFilter
- TaggedArrayInput
- FacetFilter
- ButtonSingleLine
- TextMultiline
- ButtonSelect
- BottomSheetBehavior
- InfoButton
- BulletPointX
- BulletPointCheck
- Title
- LoadingIcon
- SelectFilterControls
- CORInputForm
- SdnInputForm
- Navbar
- HomeRoute
- AuthRoute
- DocumentDetails
- DocumentStepper
- AddGame
- Auth
- Effectiveness
- Export
- PokemonType
- Moves
- Member
- MoveSelector
- Type
- Natures
- Move
- PokeInfo
- Share
- Badges
- Status
- UpdateSW
- About
- Builder
- Calculator
- Changelog
- Import
- Pokestats
- Report
- Rules
- Settings
- Tracker
- DarkThemeProvider
- NotificationHandler
- Background
- Indicator
- StyledButton
- StyledText
- Illustration
- OnboardingSlider
- FlexList
- AppLayout
- ScrollableList
- Visualization
- DataSearch
- Region
- App
- CompareApiLegend
- CompareApiBreadcrumbs
- CompareApiLink
- CompareApiCard
- ExploreApiBreadcrumbs
- ExploreApiLink
- ExploreApiSearch
- ExploreApiConst
- ApiLoader
- RefreshButton
- Listing
- PriceModal
- ConfirmationModal
- Transition
- AutoComplete
- useInput
- Avatar
- Badge
- Breadcrumbs
- ButtonDropdown
- ButtonGroup
- Capacity
- Checkbox
- Code
- Collapse
- CssBaseline
- GeistProvider
- Description
- Display
- Divider
- Dot
- Drawer
- useModal
- Fieldset
- Grid
- Image
- Keyboard
- Link
- Modal
- Note
- Page
- Pagination
- Popover
- Progress
- Radio
- Rating
- Slider
- Snippet
- Spacer
- Spinner
- Tabs
- Textarea
- Tooltip
- Tree
- useBodyScroll
- useClasses
- useClickAway
- useClipboard
- useCurrentState
- useKeyboard
- KeyMod
- KeyCode
- useMediaQuery
- useTabs
- useToasts
- User
- useTheme
- Themes
- GeistUIThemes
- useAllThemes
- CollapsableDialog
- Map
- IPForm
- IPMenu
- Container
- Parallax
- Nav
- SEO
- BlogNav
- ExtensionCard
- MenuComp
Other Related APIs
components#Slider TypeScript Examples
The following examples show how to use
components#Slider.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.test.tsx From geist-ui with MIT License | 4 votes |
describe('Slider', () => {
beforeAll(() => {
window.Element.prototype.getBoundingClientRect = () =>
({
x: 0,
y: 0,
width: 100,
height: 10,
top: 0,
bottom: 10,
left: 0,
right: 100,
} as DOMRect)
})
it('should render correctly', () => {
const wrapper = mount(<Slider initialValue={20} />)
expect(wrapper.html()).toMatchSnapshot()
expect(() => wrapper.unmount()).not.toThrow()
})
it('should trigger events when click', async () => {
let value = 0
const changeHandler = jest.fn().mockImplementation(val => (value = val))
const wrapper = mount(<Slider initialValue={20} onChange={changeHandler} />)
wrapper.find('.slider').simulate('click', {
...nativeEvent,
clientX: 50,
})
await updateWrapper(wrapper, 350)
expect(changeHandler).toHaveBeenCalled()
expect(value).toEqual(50)
changeHandler.mockRestore()
})
it('should trigger events when drag', async () => {
let value = 0
const changeHandler = jest.fn().mockImplementation(val => (value = val))
const wrapper = mount(<Slider initialValue={0} onChange={changeHandler} />)
const dot = wrapper.find('.dot').getDOMNode() as HTMLDivElement
act(() => triggerDrag(dot, 50))
expect(changeHandler).toHaveBeenCalled()
expect(value).toEqual(50)
changeHandler.mockRestore()
})
it('should work with different status', () => {
const wrapper = mount(
<div>
<Slider type="secondary" />
<Slider type="success" />
<Slider type="warning" />
<Slider type="error" />
</div>,
)
expect(wrapper.html()).toMatchSnapshot()
})
it('should ignore events when disabled', async () => {
let value = 0
const changeHandler = jest.fn().mockImplementation(val => (value = val))
const wrapper = mount(<Slider initialValue={0} disabled onChange={changeHandler} />)
const dot = wrapper.find('.dot').getDOMNode() as HTMLDivElement
act(() => triggerDrag(dot, 50))
expect(changeHandler).not.toHaveBeenCalled()
expect(value).not.toEqual(50)
wrapper.find('.slider').simulate('click', {
...nativeEvent,
clientX: 50,
})
await updateWrapper(wrapper, 350)
expect(changeHandler).not.toHaveBeenCalled()
expect(value).not.toEqual(50)
changeHandler.mockRestore()
})
it('should move unit length is step', async () => {
let value = 0
const changeHandler = jest.fn().mockImplementation(val => (value = val))
const wrapper = mount(<Slider step={10} onChange={changeHandler} />)
const dot = wrapper.find('.dot').getDOMNode() as HTMLDivElement
act(() => triggerDrag(dot, 6))
expect(changeHandler).toHaveBeenCalled()
expect(value).toEqual(10)
changeHandler.mockRestore()
})
it('should return the specified when the limit is exceeded', () => {
let value = 0
const changeHandler = jest.fn().mockImplementation(val => (value = val))
const wrapper = mount(<Slider min={10} max={20} onChange={changeHandler} />)
const dot = wrapper.find('.dot').getDOMNode() as HTMLDivElement
act(() => triggerDrag(dot, -5))
expect(changeHandler).toHaveBeenCalled()
expect(value).toEqual(10)
act(() => triggerDrag(dot, 101))
expect(changeHandler).toHaveBeenCalled()
expect(value).toEqual(20)
changeHandler.mockRestore()
})
it('should render number in dot', () => {
let wrapper = mount(<Slider initialValue={20} />)
expect(wrapper.find('.dot').text()).toContain('20')
wrapper = mount(<Slider value={50} />)
expect(wrapper.find('.dot').text()).toContain('50')
})
it('should work with markers', () => {
let wrapper = mount(<Slider step={10} showMarkers />)
expect(wrapper.html()).toMatchSnapshot()
wrapper = mount(<Slider step={20} showMarkers />)
expect(wrapper.html()).toMatchSnapshot()
})
it('should work with hideValue', () => {
let wrapper = mount(<Slider initialValue={20} hideValue />)
expect(wrapper.html()).toMatchSnapshot()
})
})