Skip to content

Commit 49bd0a4

Browse files
Merge pull request #29 from ai-action/feat/placeholder
2 parents 873cb5a + 981711b commit 49bd0a4

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

src/components/Chat/Input.test.tsx

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ vi.mock('@inkjs/ui', () => ({
1111
isDisabled,
1212
onChange,
1313
onSubmit,
14+
placeholder,
1415
}: {
1516
defaultValue?: string;
1617
isDisabled?: boolean;
1718
onChange?: (value: string) => void;
1819
onSubmit?: (value: string) => void;
20+
placeholder?: string;
1921
}) => {
2022
const [value, setValue] = useState(defaultValue ?? '');
2123
const valueRef = useRef(defaultValue ?? '');
@@ -56,7 +58,16 @@ vi.mock('@inkjs/ui', () => ({
5658
setValue(nextValue);
5759
});
5860

59-
return <Text>{value}</Text>;
61+
return (
62+
<>
63+
<Text>{value === '' ? (placeholder ?? '') : value}</Text>
64+
{value ? (
65+
<Text dimColor>{`[value:${value}]`}</Text>
66+
) : (
67+
<Text dimColor>{`[placeholder:${placeholder ?? ''}]`}</Text>
68+
)}
69+
</>
70+
);
6071
},
6172
}));
6273

@@ -169,6 +180,10 @@ describe('Input', () => {
169180
it('renders input prompt', () => {
170181
const { lastFrame } = render(<Input onSubmit={vi.fn()} />);
171182
expect(lastFrame()).toContain('>');
183+
expect(lastFrame()).toContain('Ask anything... (/ commands, @ files)');
184+
expect(lastFrame()).toContain(
185+
'[placeholder:Ask anything... (/ commands, @ files)]',
186+
);
172187
});
173188

174189
it('does not show command suggestion on non-slash input', async () => {
@@ -337,9 +352,13 @@ describe('Input', () => {
337352
await test.tick();
338353
stdin.write('i');
339354
await test.tick();
355+
expect(lastFrame()).toContain('[value:hi]');
340356
stdin.write(KEY.ENTER);
341357
await test.tick(10);
342-
expect(lastFrame()).not.toContain('hi');
358+
expect(lastFrame()).not.toContain('[value:hi]');
359+
expect(lastFrame()).toContain(
360+
'[placeholder:Ask anything... (/ commands, @ files)]',
361+
);
343362
});
344363

345364
it('deletes last character on backspace', async () => {
@@ -375,7 +394,10 @@ describe('Input', () => {
375394
);
376395
stdin.write('h');
377396
await test.tick();
378-
expect(lastFrame()).not.toContain('h');
397+
expect(lastFrame()).not.toContain('[value:h]');
398+
expect(lastFrame()).toContain(
399+
'[placeholder:Ask anything... (/ commands, @ files)]',
400+
);
379401
stdin.write(KEY.ENTER);
380402
await test.tick();
381403
expect(onSubmit).not.toHaveBeenCalled();

src/components/Chat/Input.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export function Input({ isDisabled = false, onSubmit }: Props) {
7171
key={resetKey}
7272
onChange={setInput}
7373
onSubmit={handleSubmitText}
74+
placeholder="Ask anything... (/ commands, @ files)"
7475
/>
7576
</Box>
7677

0 commit comments

Comments
 (0)