Skip to content

Commit

Permalink
Merge pull request #342 from Capgemini/feature/button-value
Browse files Browse the repository at this point in the history
feat: button-value
  • Loading branch information
daniele-zurico authored Sep 20, 2022
2 parents df663fe + 5d02929 commit 94d80f6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ type ButtonProps = React.HTMLAttributes<HTMLButtonElement> & {
* allow the user to define the buttons name
*/
name?: string;
/**
* allow the user to define the button value
*/
value?: string | number;
};

export const Button = ({
Expand All @@ -81,6 +85,7 @@ export const Button = ({
customLoadingPostImage,
formAction,
name,
value,
...props
}: ButtonProps) => {
const [disable, setDisable] = React.useState<boolean>(disabled);
Expand Down Expand Up @@ -130,6 +135,7 @@ export const Button = ({
aria-label={ariaLabel}
formAction={formAction}
name={name}
value={value}
{...props}
>
{prefix}
Expand Down
7 changes: 7 additions & 0 deletions src/button/__tests__/Button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,11 @@ describe('Button', () => {
const button: any = screen.getByRole('button');
expect(button.getAttribute('name')).toBe('submit');
});

it('should accept value as attribute', () => {
const handleClick = jest.fn();
render(<Button onClick={handleClick} value='buttonValue'/>);
const button: any = screen.getByRole('button');
expect(button.getAttribute('value')).toBe('buttonValue');
});
});
3 changes: 2 additions & 1 deletion stories/Button/Documentation.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ An example with all the available properties is:
onClick={buttonHandler}
disableClickForMs={2000}
disable={true}
isLoading={true},
isLoading={true}
value={value}
loadingLabel="loading..."
customLoadingPreImage={<span>spinner</span>}
customLoadingPostImage={<span>spinner</span>}
Expand Down
1 change: 1 addition & 0 deletions stories/liveEdit/ButtonLive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function ButtonDemo() {
customPostfixImg={<></>}
customPrefixImg={<></>}
isLoading={isLoading}
value={value}
loadingLabel="saving..."
customLoadingPreImage={<></>}
customLoadingPostImage={<></>}
Expand Down

0 comments on commit 94d80f6

Please # to comment.