mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
parent
4a3ce66193
commit
5f61266931
@ -15,6 +15,16 @@ jest.mock('../../utils/measureText', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('AutoSizeInput', () => {
|
describe('AutoSizeInput', () => {
|
||||||
|
it('should support default Input API', () => {
|
||||||
|
const onChange = jest.fn();
|
||||||
|
render(<AutoSizeInput onChange={onChange} value="" />);
|
||||||
|
|
||||||
|
const input: HTMLInputElement = screen.getByTestId('autosize-input');
|
||||||
|
fireEvent.change(input, { target: { value: 'foo' } });
|
||||||
|
|
||||||
|
expect(onChange).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
it('should have default minWidth when empty', () => {
|
it('should have default minWidth when empty', () => {
|
||||||
render(<AutoSizeInput />);
|
render(<AutoSizeInput />);
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ export const AutoSizeInput = React.forwardRef<HTMLInputElement, Props>((props, r
|
|||||||
minWidth = 10,
|
minWidth = 10,
|
||||||
maxWidth,
|
maxWidth,
|
||||||
onCommitChange,
|
onCommitChange,
|
||||||
|
onChange,
|
||||||
onKeyDown,
|
onKeyDown,
|
||||||
onBlur,
|
onBlur,
|
||||||
value: controlledValue,
|
value: controlledValue,
|
||||||
@ -48,6 +49,9 @@ export const AutoSizeInput = React.forwardRef<HTMLInputElement, Props>((props, r
|
|||||||
ref={ref}
|
ref={ref}
|
||||||
value={value.toString()}
|
value={value.toString()}
|
||||||
onChange={(event) => {
|
onChange={(event) => {
|
||||||
|
if (onChange) {
|
||||||
|
onChange(event);
|
||||||
|
}
|
||||||
setValue(event.currentTarget.value);
|
setValue(event.currentTarget.value);
|
||||||
}}
|
}}
|
||||||
width={inputWidth}
|
width={inputWidth}
|
||||||
|
Loading…
Reference in New Issue
Block a user