Skip to content

Commit f787ffa

Browse files
stbfbmeta-codesync[bot]
authored andcommitted
Add clear button to commit tree search filter
Summary: Add an inline clear button (X icon) to the commit tree search filter input. When the filter text is non-empty, a small close button appears inside the text field allowing users to quickly clear the filter with a single click instead of manually selecting and deleting the text. Reviewed By: DerekCYu Differential Revision: D95960785 fbshipit-source-id: 73fa21bbb4b3a4d72023eeadffdf9d8c448e3057
1 parent 377c44e commit f787ffa

File tree

1 file changed

+41
-7
lines changed

1 file changed

+41
-7
lines changed

addons/isl/src/CommitTreeSearchFilter.tsx

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
import * as stylex from '@stylexjs/stylex';
9+
import {Button} from 'isl-components/Button';
910
import {Icon} from 'isl-components/Icon';
1011
import {TextField} from 'isl-components/TextField';
1112
import {atom, useAtom} from 'jotai';
@@ -19,9 +20,31 @@ const styles = stylex.create({
1920
alignItems: 'center',
2021
gap: '4px',
2122
},
23+
inputContainer: {
24+
position: 'relative',
25+
display: 'flex',
26+
alignItems: 'center',
27+
},
2228
input: {
2329
minWidth: '80px',
2430
width: '150px',
31+
paddingRight: '24px',
32+
},
33+
clearButton: {
34+
position: 'absolute',
35+
right: '2px',
36+
display: 'flex',
37+
alignItems: 'center',
38+
justifyContent: 'center',
39+
cursor: 'pointer',
40+
background: 'none',
41+
border: 'none',
42+
padding: '2px',
43+
color: 'var(--foreground)',
44+
opacity: {
45+
default: 0.7,
46+
':hover': 1,
47+
},
2548
},
2649
});
2750

@@ -30,13 +53,24 @@ export function CommitTreeSearchFilterInput() {
3053
return (
3154
<div {...stylex.props(styles.container)}>
3255
<Icon icon="search" />
33-
<TextField
34-
xstyle={styles.input}
35-
placeholder={t('Filter commits...')}
36-
value={filter}
37-
onInput={e => setFilter(e.currentTarget?.value ?? '')}
38-
data-testid="commit-tree-search-filter"
39-
/>
56+
<div {...stylex.props(styles.inputContainer)}>
57+
<TextField
58+
xstyle={styles.input}
59+
placeholder={t('Filter commits...')}
60+
value={filter}
61+
onInput={e => setFilter(e.currentTarget?.value ?? '')}
62+
data-testid="commit-tree-search-filter"
63+
/>
64+
{filter !== '' && (
65+
<Button
66+
icon
67+
xstyle={styles.clearButton}
68+
onClick={() => setFilter('')}
69+
aria-label={t('Clear filter')}>
70+
<Icon icon="close" size="S" />
71+
</Button>
72+
)}
73+
</div>
4074
</div>
4175
);
4276
}

0 commit comments

Comments
 (0)