From 979b3e3306d9e00cabf15cac8ae0c231c86b4c81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20H=C3=B8egh?= Date: Wed, 17 Jan 2024 14:39:32 +0100 Subject: [PATCH] fix(Input): should not clear input value with escape key (#3235) --- .../src/docs/uilib/components/input/demos.mdx | 2 +- .../dnb-eufemia/src/components/input/Input.js | 3 --- .../src/components/input/__tests__/Input.test.tsx | 15 --------------- 3 files changed, 1 insertion(+), 19 deletions(-) diff --git a/packages/dnb-design-system-portal/src/docs/uilib/components/input/demos.mdx b/packages/dnb-design-system-portal/src/docs/uilib/components/input/demos.mdx index 24e408fa5a1..759c9f8cbe6 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/components/input/demos.mdx +++ b/packages/dnb-design-system-portal/src/docs/uilib/components/input/demos.mdx @@ -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. diff --git a/packages/dnb-eufemia/src/components/input/Input.js b/packages/dnb-eufemia/src/components/input/Input.js index b689720bb27..a457df34f1f 100644 --- a/packages/dnb-eufemia/src/components/input/Input.js +++ b/packages/dnb-eufemia/src/components/input/Input.js @@ -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 diff --git a/packages/dnb-eufemia/src/components/input/__tests__/Input.test.tsx b/packages/dnb-eufemia/src/components/input/__tests__/Input.test.tsx index 4b716637857..a13f5204d45 100644 --- a/packages/dnb-eufemia/src/components/input/__tests__/Input.test.tsx +++ b/packages/dnb-eufemia/src/components/input/__tests__/Input.test.tsx @@ -513,21 +513,6 @@ describe('Input with clear button', () => { expect(clearButton).toHaveAttribute('disabled') }) - it('should clear the value on escape key press', () => { - render() - - 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()