-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Makes button dropdown main action clickable with Enter (#2897)
- Loading branch information
Showing
3 changed files
with
75 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,48 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import * as React from 'react'; | ||
import React, { useState } from 'react'; | ||
|
||
import ButtonDropdown from '~components/button-dropdown'; | ||
import { Box, Button, ButtonDropdown, SpaceBetween } from '~components'; | ||
import InternalButtonDropdown from '~components/button-dropdown/internal'; | ||
|
||
export default function ButtonDropdownPage() { | ||
const [clickedButton, setClickedButton] = useState(''); | ||
return ( | ||
<> | ||
<h1>Button dropdown with main action</h1> | ||
<ButtonDropdown | ||
items={[ | ||
{ | ||
text: 'Launch instance from template', | ||
id: 'launch-instance-from-template', | ||
}, | ||
]} | ||
mainAction={{ text: 'Launch instance' }} | ||
ariaLabel="More launch options" | ||
variant="primary" | ||
/> | ||
<Box margin="m"> | ||
<h1>Button dropdown with main action</h1> | ||
<SpaceBetween size="m"> | ||
<Button data-testid="focus-before" variant="inline-link"> | ||
focus before | ||
</Button> | ||
|
||
<ButtonDropdown | ||
data-testid="with-main-action-and-dropdown" | ||
items={[ | ||
{ | ||
text: 'Launch instance from template', | ||
id: 'launch-instance-from-template', | ||
}, | ||
]} | ||
onItemClick={() => setClickedButton('Launch instance from template')} | ||
mainAction={{ text: 'Launch instance', onClick: () => setClickedButton('Launch instance') }} | ||
ariaLabel="More launch options" | ||
variant="primary" | ||
/> | ||
|
||
<InternalButtonDropdown | ||
data-testid="with-main-action-only" | ||
items={[]} | ||
mainAction={{ | ||
text: 'Launch instance (main action only)', | ||
onClick: () => setClickedButton('Launch instance (main action only)'), | ||
}} | ||
showMainActionOnly={true} | ||
/> | ||
|
||
<div id="clicked">{clickedButton}</div> | ||
</SpaceBetween> | ||
</Box> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters