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

keyboard navigation: feature/focus states #589

Merged
merged 12 commits into from
Oct 29, 2024
Merged

Conversation

interim17
Copy link
Contributor

Time estimate or Size

medium/small

Problem

Closes #575 and #576, advances #347
Part of keyboard navigation and accessibility work.

Solution

Focus styling for action buttons has been reviewed with Lyndsay but is not reflected in master Figma yet.
Styling for primary/secondary buttons, and dropdown elements is there.
Style guide

Closing #576 because they already work, its clear how to tab through them now that the visual style is obivous.

Disabled buttons are taking focus/styling for now, this can be discussed more in future as we get into navigation behavior.

  • New feature (non-breaking change which adds functionality)

CustomDropdown

Wrapper for our Dropdowns, unifies the stylesheets, just a slight DRYing now, but will be very useful going forward.

Steps to Verify:

  1. Tab through header and try action buttons (AICS home link, Simularium home link, Download, Share)
  2. Open dropdowns and check on hover and focus styling (focus styling is difficult to maintain sometimes with mouse interactions. Easiest way to see it is the use the buttons that open the submenus.

Applying focus styling to ALL interactive elements is out of scope for this PR (e.g. submenu items in drop-downs)

Screenshots (optional):

Screenshot 2024-10-16 at 2 51 56 PM Screenshot 2024-10-16 at 2 51 50 PM Screenshot 2024-10-16 at 2 51 43 PM

Comment on lines -76 to -82
//Dropdown
@dropdown-menu-bg: @dark-four;
@dropdown-vertical-padding: 5px;
@dropdown-edge-child-vertical-padding: 4px;
@dropdown-font-size: @font-size-base;
@dropdown-line-height: 22px;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Continuing to pivot away from .less in anticipation of migrating to antd 5

Copy link

github-actions bot commented Oct 16, 2024

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
66.27% (-0.46% 🔻)
676/1020
🟡 Branches
65.31% (-1.36% 🔻)
96/147
🔴 Functions
35% (-0.25% 🔻)
91/260
🟡 Lines
64.66% (-0.41% 🔻)
602/931

Test suite run success

121 tests passing in 7 suites.

Report generated by 🧪jest coverage report action from c2ac2a0

Comment on lines +82 to +84
.nav-button.dropdown-item-button:global(.ant-btn) {
background-color: inherit;
border: inherit;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In some cases we were using <a> to open modals but for accessibility those should be a buttons, even if its easier to style when they are all the same element type. I also felt the styling for all the differenet elements that can be dropdown menu items should be in the CustomDropdown stylesheet.

Using <NavButton />, making the new DropdownItem button class, and using these two inherit rules seemed to be the most concise way to manage selector specificity and keep the styling where I wanted it. Open to suggestions.

@interim17 interim17 marked this pull request as ready for review October 16, 2024 22:06
@interim17 interim17 requested a review from a team as a code owner October 16, 2024 22:06
@interim17 interim17 requested review from toloudis and frasercl and removed request for a team October 16, 2024 22:06
@interim17 interim17 changed the title feature/focus states keyboard navigation: feature/focus states Oct 23, 2024
Comment on lines 19 to 44
const CustomDropdown: React.FC<CustomDropdownProps> = ({
items,
titleText,
icon,
buttonType,
placement,
disabled,
narrow,
}) => {
const menuClassNames = narrow
? classNames(styles.menu, styles.narrow)
: styles.menu;
return (
<Dropdown
menu={{ items, theme: "dark", className: menuClassNames }}
placement={placement}
disabled={disabled}
>
<NavButton
titleText={titleText}
icon={icon}
buttonType={buttonType}
/>
</Dropdown>
);
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Like our CustomModal and NavButton this wrapper is mostly to DRY out the code, and will be a vehicle for code for things that antd doesn't provide but can be generalized to all dropdowns.

Comment on lines 8 to 10
.menu.narrow {
width: calc(var(--dropdown-menu-width) - 50px);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This file replaces the now deleted stylesheets for HelpMenu and LoadFileMenu.

This was the only style difference between the two to manage for now.

@ShrimpCryptid ShrimpCryptid requested review from ShrimpCryptid and removed request for frasercl October 28, 2024 21:35
Copy link
Contributor

@toloudis toloudis left a comment

Choose a reason for hiding this comment

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

Taking for granted that everything works, I see no obvious code smells. LGTM!

Copy link
Contributor

@ShrimpCryptid ShrimpCryptid left a comment

Choose a reason for hiding this comment

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

Left some non-blocking comments but love the accessibility changes.

</Dropdown>
<CustomDropdown
items={items}
titleText={"Help "}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should CustomDropdown/NavButton just add spacing between the titleText and the icon?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why don't we just remove that silly space instead.

}

.menu.narrow {
width: calc(var(--dropdown-menu-width) - 50px);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: This seems a little magic number-y, would it make more sense to either define a narrow width variable or make the width set by fit-content or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Much better, thank you

Comment on lines -120 to -131
<Dropdown
menu={{ items, theme: "dark", className: styles.menu }}
<CustomDropdown
items={items}
titleText={"Load model"}
icon={DownArrow}
buttonType={ButtonClass.Primary}
placement="bottomRight"
disabled={isDisabled}
>
<NavButton
titleText={"Load model"}
icon={DownArrow}
buttonType={ButtonClass.Primary}
isDisabled={isDisabled}
/>
</Dropdown>
Copy link
Contributor

Choose a reason for hiding this comment

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

Really like that the NavButton gets collapsed into Dropdown in all the instances here :')

@@ -117,18 +117,14 @@ const LoadFileMenu = ({

return (
<>
<Dropdown
menu={{ items, theme: "dark", className: styles.menu }}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we lose the dark theming here on the dropdown?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No we don't, although we are overriding most of it anyway.

color: var(--dark-theme-action-button-hover-color);
}

.nav-button.action-button:global(.ant-btn:focus) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider changing the focus selectors to focus-visible, which will make it only respond to keyboard focusing (and not if the user last clicked on the button)

https://developer.mozilla.org/en-US/docs/Web/CSS/:focus-visible

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FYI: I updated the lines relevant to this PR , but not every place that :focus exists in the code base although I have that in mind now for this ongoing work.

@interim17 interim17 merged commit 696f7bd into main Oct 29, 2024
6 checks passed
@interim17 interim17 deleted the feature/focus-states branch October 29, 2024 23:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

more visually explicit focus states for focused elements that differs from hover state
3 participants