Skip to content

Commit

Permalink
fix(Input): should not clear input value with escape key (#3235)
Browse files Browse the repository at this point in the history
  • Loading branch information
tujoworker authored Jan 17, 2024
1 parent fde9aae commit 979b3e3
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Pressing the enter key will trigger a submit.

### Input with clear button

Pushing the clear button or pressing the ESC key will clear the input.
Pushing the clear button will clear the input.

<InputExampleClear />

Expand Down
3 changes: 0 additions & 3 deletions packages/dnb-eufemia/src/components/input/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,6 @@ export default class Input extends React.PureComponent {
if (event.key === 'Enter') {
dispatchCustomElementEvent(this, 'on_submit', { value, event })
}
if (isTrue(this.props.clear) && event.key === 'Escape') {
this.clearValue(event)
}
}
clearValue = (event) => {
const previousValue = this.state.value
Expand Down
15 changes: 0 additions & 15 deletions packages/dnb-eufemia/src/components/input/__tests__/Input.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -513,21 +513,6 @@ describe('Input with clear button', () => {
expect(clearButton).toHaveAttribute('disabled')
})

it('should clear the value on escape key press', () => {
render(<Input clear={true} value="value" />)

expect(document.querySelector('input').getAttribute('value')).toBe(
'value'
)

fireEvent.keyDown(document.querySelector('input'), {
key: 'Escape',
keyCode: 27, // escape
})

expect(document.querySelector('input').getAttribute('value')).toBe('')
})

it('should set focus on input when clear button is pressed', () => {
render(<Input id="input-id" clear={true} value="value" />)

Expand Down

0 comments on commit 979b3e3

Please sign in to comment.