-
Notifications
You must be signed in to change notification settings - Fork 843
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EuiRange/EuiDualRange] Improve UX of input widths on EuiRange/EuiDua…
…lRange - account for `invalid` icon (which now automatically displays for out of range inputs) - dynamically adjust width based on # of characters in actual input - adjust width affordances based on `compressed` - width changes are especially a readability improvement in Firefox
- Loading branch information
Showing
7 changed files
with
203 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/components/form/range/__snapshots__/range_input.test.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`EuiRangeInput renders 1`] = ` | ||
<div | ||
class="euiFormControlLayout" | ||
> | ||
<div | ||
class="euiFormControlLayout__childrenWrapper" | ||
> | ||
<input | ||
aria-invalid="false" | ||
class="euiFieldNumber euiRangeInput euiRangeInput--max emotion-euiRangeInput" | ||
max="100" | ||
min="0" | ||
style="inline-size: calc(12px + 1ch + 2em + 0px);" | ||
type="number" | ||
value="0" | ||
/> | ||
</div> | ||
</div> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { render } from '../../../test/rtl'; | ||
import { shouldRenderCustomStyles } from '../../../test/internal'; | ||
|
||
import { EuiRangeInput } from './range_input'; | ||
|
||
const requiredProps = { | ||
min: 0, | ||
max: 100, | ||
value: 0, | ||
onChange: () => {}, | ||
}; | ||
|
||
describe('EuiRangeInput', () => { | ||
shouldRenderCustomStyles(<EuiRangeInput {...requiredProps} />); | ||
|
||
it('renders', () => { | ||
const { container } = render(<EuiRangeInput {...requiredProps} />); | ||
expect(container.firstChild).toMatchSnapshot(); | ||
}); | ||
|
||
describe('widthStyle', () => { | ||
it('does not set a width style if the `autoSize` is set to false', () => { | ||
const { container } = render( | ||
<EuiRangeInput {...requiredProps} autoSize={false} /> | ||
); | ||
const widthStyle = container | ||
.querySelector('.euiRangeInput') | ||
?.getAttribute('style'); | ||
|
||
expect(widthStyle).toBeFalsy(); | ||
}); | ||
|
||
it('increases input character width dynamically based on value', () => { | ||
const { rerender, container } = render( | ||
<EuiRangeInput {...requiredProps} value="0" /> | ||
); | ||
const getWidthStyle = () => | ||
container.querySelector('.euiRangeInput')?.getAttribute('style'); | ||
|
||
expect(getWidthStyle()).toMatchInlineSnapshot( | ||
'"inline-size: calc(12px + 1ch + 2em + 0px);"' | ||
); | ||
|
||
rerender(<EuiRangeInput {...requiredProps} value="10" />); | ||
expect(getWidthStyle()).toMatchInlineSnapshot( | ||
'"inline-size: calc(12px + 2ch + 2em + 0px);"' | ||
); | ||
|
||
rerender(<EuiRangeInput {...requiredProps} value="100" />); | ||
expect(getWidthStyle()).toMatchInlineSnapshot( | ||
'"inline-size: calc(12px + 3ch + 2em + 0px);"' | ||
); | ||
|
||
rerender(<EuiRangeInput {...requiredProps} value="1000" />); | ||
expect(getWidthStyle()).toMatchInlineSnapshot( | ||
'"inline-size: calc(12px + 4ch + 2em + 22px);"' | ||
); | ||
|
||
// Should not go above 4 characters in width | ||
rerender(<EuiRangeInput {...requiredProps} value="10000" />); | ||
expect(getWidthStyle()).toMatchInlineSnapshot( | ||
'"inline-size: calc(12px + 4ch + 2em + 22px);"' | ||
); | ||
}); | ||
|
||
test('compressed', () => { | ||
const { container } = render( | ||
<EuiRangeInput {...requiredProps} compressed /> | ||
); | ||
const widthStyle = container | ||
.querySelector('.euiRangeInput') | ||
?.getAttribute('style'); | ||
|
||
expect(widthStyle).toMatchInlineSnapshot( | ||
'"inline-size: calc(8px + 1ch + 2em + 0px);"' | ||
); | ||
}); | ||
|
||
test('invalid', () => { | ||
const { container } = render( | ||
<EuiRangeInput {...requiredProps} isInvalid /> | ||
); | ||
const widthStyle = container | ||
.querySelector('.euiRangeInput') | ||
?.getAttribute('style'); | ||
|
||
expect(widthStyle).toMatchInlineSnapshot( | ||
'"inline-size: calc(12px + 1ch + 2em + 22px);"' | ||
); | ||
}); | ||
|
||
test('invalid + compressed', () => { | ||
const { container } = render( | ||
<EuiRangeInput {...requiredProps} isInvalid compressed /> | ||
); | ||
const widthStyle = container | ||
.querySelector('.euiRangeInput') | ||
?.getAttribute('style'); | ||
|
||
expect(widthStyle).toMatchInlineSnapshot( | ||
'"inline-size: calc(8px + 1ch + 2em + 18px);"' | ||
); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.