Skip to content

Commit

Permalink
Merge pull request #11 from michaela9/5-disable-button
Browse files Browse the repository at this point in the history
disable button when input is empty
  • Loading branch information
tomastauer authored Apr 4, 2024
2 parents 82ae8ac + 2334d25 commit 01bef19
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 @@ -29,7 +30,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 01bef19

Please sign in to comment.