Skip to content

Commit e17ae7d

Browse files
committed
Refactor the ChatInput component by relocating the clear button implementation and associated styles
1 parent 05f489d commit e17ae7d

3 files changed

Lines changed: 42 additions & 1 deletion

File tree

‎packages/ui/src/components/editor/panel/ChatInput/ChatInput.module.scss‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,29 @@
7676
}
7777
}
7878

79+
.clear-button {
80+
position: absolute;
81+
top: 0;
82+
right: 0;
83+
z-index: 2;
84+
width: 18px;
85+
height: 18px;
86+
display: flex;
87+
align-items: center;
88+
justify-content: center;
89+
cursor: pointer;
90+
color: var(--vscode-icon-foreground);
91+
opacity: var(--dimmed-opacity);
92+
93+
&::before {
94+
font-size: 13px !important;
95+
}
96+
97+
&:hover {
98+
opacity: 1;
99+
}
100+
}
101+
79102
.highlight-container {
80103
position: absolute;
81104
top: 0;

‎packages/ui/src/components/editor/panel/ChatInput/ChatInput.tsx‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export const ChatInput: React.FC<ChatInputProps> = (props) => {
4949
handle_select_click
5050
} = use_dropdown(props)
5151
const {
52+
handle_clear,
5253
handle_select,
5354
handle_input_change,
5455
handle_submit,
@@ -173,6 +174,16 @@ export const ChatInput: React.FC<ChatInputProps> = (props) => {
173174
}}
174175
ref={container_ref}
175176
>
177+
{props.value && (
178+
<button
179+
className={cn(styles['clear-button'], 'codicon', 'codicon-close')}
180+
onClick={() => {
181+
handle_clear()
182+
textarea_ref.current?.focus()
183+
}}
184+
title="Clear"
185+
/>
186+
)}
176187
<div className={styles['highlight-container']} ref={highlight_ref}>
177188
{get_highlighted_text({
178189
text: props.value,

‎packages/ui/src/components/editor/panel/ChatInput/hooks/use-handlers.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ export const use_handlers = (props: ChatInputProps) => {
1111
props.on_caret_position_change(caret_position)
1212
}
1313

14+
const handle_clear = () => {
15+
props.on_change('')
16+
set_history_index(-1)
17+
set_is_history_enabled(true)
18+
}
19+
1420
const handle_input_change = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
1521
const new_value = e.target.value
1622
props.on_change(new_value)
@@ -103,6 +109,7 @@ export const use_handlers = (props: ChatInputProps) => {
103109
handle_input_change,
104110
handle_submit,
105111
handle_key_down,
106-
is_history_enabled
112+
is_history_enabled,
113+
handle_clear
107114
}
108115
}

0 commit comments

Comments
 (0)