Skip to content

Commit 60b88b1

Browse files
committed
Support clearing the filter input by pressing Escape
1 parent 57c19aa commit 60b88b1

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
55

66
## [Unreleased]
7+
8+
## [1.3.0] - 2021-10-02
79
### Added
810
- Add webextension-polyfill.
11+
- Pressing Escape clears the search input.
912

1013
## [1.2.0] - 2021-09-18
1114
### Added
@@ -42,7 +45,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
4245
### Added
4346
- Initial release.
4447

45-
[Unreleased]: https://github.com/msmolens/treetop/compare/v1.2.0...HEAD
48+
[Unreleased]: https://github.com/msmolens/treetop/compare/v1.3.0...HEAD
49+
[1.3.0]: https://github.com/msmolens/treetop/releases/tag/v1.3.0
4650
[1.2.0]: https://github.com/msmolens/treetop/releases/tag/v1.2.0
4751
[1.1.3]: https://github.com/msmolens/treetop/releases/tag/v1.1.3
4852
[1.1.2]: https://github.com/msmolens/treetop/releases/tag/v1.1.2

src/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"manifest_version": 2,
33
"name": "Treetop",
44
"description": "__MSG_extensionDescription__",
5-
"version": "1.2.0",
5+
"version": "1.3.0",
66
"author": "Max Smolens",
77
"homepage_url": "https://github.com/msmolens/treetop",
88
"default_locale": "en",

src/treetop/FilterInput.svelte

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@
6969
dispatchInputEvent();
7070
}
7171
72+
/**
73+
* Clear filter input when user presses Escape.
74+
*/
75+
function onKeyDown(e: KeyboardEvent) {
76+
if (e.key === 'Escape') {
77+
clearFilterInput();
78+
}
79+
}
80+
7281
/**
7382
* Debounced filter input handler.
7483
*/
@@ -88,6 +97,7 @@
8897
<TextField
8998
bind:value={filter}
9099
on:input={debounceFilterInput}
100+
on:keydown={onKeyDown}
91101
label={browser.i18n.getMessage('search')}>
92102
<IconButton
93103
bind:this={iconButton}

test/treetop/FilterInput.svelte.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,33 @@ it('clears the input when the clear button is pressed', async () => {
127127
expect(screen.queryByRole('button')).not.toBeInTheDocument();
128128
});
129129
});
130+
131+
it('clears the input when the escape is pressed', async () => {
132+
const { component } = setup();
133+
134+
const callback = jest.fn();
135+
component.$on('input', callback);
136+
137+
const input = screen.getByLabelText(/^search$/i);
138+
139+
const words = faker.random.words();
140+
// eslint-disable-next-line @typescript-eslint/await-thenable
141+
await userEvent.type(input, words);
142+
userEvent.keyboard('[Enter]');
143+
144+
await waitFor(() => {
145+
expect(screen.getByRole('button')).toBeInTheDocument();
146+
});
147+
148+
expect(callback).toHaveBeenCalledTimes(1);
149+
150+
userEvent.keyboard('{Escape}');
151+
152+
await waitFor(() => {
153+
expect(callback).toHaveBeenCalledTimes(2);
154+
});
155+
156+
await waitFor(() => {
157+
expect(screen.queryByRole('button')).not.toBeInTheDocument();
158+
});
159+
});

0 commit comments

Comments
 (0)