Skip to content

Commit

Permalink
disable button when input is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
michaela9 committed Apr 4, 2024
1 parent 862cfba commit 2334d25
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/app/components/add-item.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use client';

import { useState } from 'react';
import { Input } from './input';

import { Button } from './button';
import { Input } from './input';

type Props = {
onAddItem: (content: string) => void;
Expand All @@ -27,7 +28,9 @@ export function AddItem({ onAddItem: addItem }: Props) {
onValueChange={handleOnValueChange}
onEnter={handleAdd}
/>
<Button onClick={handleAdd}>Add item</Button>
<Button disabled={!value} onClick={handleAdd}>
Add item
</Button>
</div>
);
}
4 changes: 3 additions & 1 deletion src/app/components/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import React from 'react';
type Props = {
onClick: () => void;
children: React.ReactNode;
disabled: boolean;
};

export const Button = ({ onClick, children }: Props) => (
export const Button = ({ onClick, children, disabled }: Props) => (
<button
disabled={disabled}
onClick={onClick}
data-testid="button"
className="
Expand Down

0 comments on commit 2334d25

Please sign in to comment.