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

Add the role=button to search #7594

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const MainNavigationDrawerItems = () => {
Icon={IconSearch}
onClick={toggleCommandMenu}
keyboard={['⌘', 'K']}
role="button"
/>
<NavigationDrawerItem
label="Settings"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export type NavigationDrawerItemProps = {
soon?: boolean;
count?: number;
keyboard?: string[];
role?: string;
};

type StyledItemProps = Pick<
Expand Down Expand Up @@ -148,6 +149,7 @@ export const NavigationDrawerItem = ({
count,
keyboard,
subItemState,
role,
}: NavigationDrawerItemProps) => {
const theme = useTheme();
const isMobile = useIsMobile();
Expand Down Expand Up @@ -185,6 +187,7 @@ export const NavigationDrawerItem = ({
as={to ? Link : 'div'}
Copy link
Contributor

@Devessier Devessier Oct 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting role=button is half a solution to make that component a button. Instead, we should render a <button> HTML tag when we want to display a button. The as property allows us to choose which component we want to render at the end. We should use it to display a button when we want.

Setting an HTML element's role attribute is a last resort. We should always try to use semantic HTML first, and here, using a button element makes sense.

To make it work with the current code, the NavigationDrawerItem component could take an optional as property which could be 'button' | undefined. We could use it to choose which component to render.

to={to ? to : undefined}
indentationLevel={indentationLevel}
role={role}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Ensure role is only applied when it's a non-empty string

>
{showBreadcrumb && (
<NavigationDrawerItemBreadcrumb state={subItemState} />
Expand Down