AutoSizeInput: Forward onChange event (#94459)

Forward onChange event
This commit is contained in:
Tobias Skarhed 2024-10-09 14:38:56 +02:00 committed by GitHub
parent 4a3ce66193
commit 5f61266931
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 0 deletions

View File

@ -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 />);

View File

@ -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}