Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/menu item option button type #1564

Merged
merged 2 commits into from Aug 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/menu/src/menu.tsx
Expand Up @@ -149,9 +149,16 @@ export interface StyledMenuItemProps extends PropsOf<typeof chakra.button> {}
const StyledMenuItem = forwardRef<StyledMenuItemProps, "button">(
function StyledMenuItem(props, ref) {
const styles = useStyles()

// given another component, use its type if present
// else, use no type to avoid invalid html, e.g. <a type="button" />
// else, fall back to "button"
const type = props.as ? props.type ?? undefined : "button"

return (
<chakra.button
ref={ref}
type={type}
{...props}
__css={{
textDecoration: "none",
Expand Down
22 changes: 22 additions & 0 deletions packages/menu/stories/menu.stories.tsx
Expand Up @@ -304,3 +304,25 @@ export const SplitButton = () => (
</Menu>
</chakra.div>
)

export const WithinForm = () => {
return (
<form>
<fieldset>
<legend>regular MenuList with MenuItems</legend>
<Menu>
<MenuButton as={Button}>do something</MenuButton>
<MenuList>
<MenuItem>Download</MenuItem>
<MenuItem>Create a Copy</MenuItem>
<MenuItem>Mark as Draft</MenuItem>
<MenuItem>Delete</MenuItem>
<MenuItem as="a" href="#">
Attend a Workshop
</MenuItem>
</MenuList>
</Menu>
</fieldset>
</form>
)
}