Skip to content

Commit

Permalink
Misc accessibility improvements + mobile drawer fix (#7912)
Browse files Browse the repository at this point in the history
  • Loading branch information
DejayJD authored Mar 22, 2024
1 parent d62d210 commit 0c8911a
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ const AnimatedButton = ({
disabledClassName = '',
wrapperClassName = '',
stopPropagation = false,
disableAnimationOnMount = true
disableAnimationOnMount = true,
uniqueKey,
...buttonProps
}: AnimatedButtonProps) => {
const [isPaused, setIsPaused] = useState(true)
const [getDidMount, setDidMount] = useInstanceVar(false)
Expand Down Expand Up @@ -122,7 +124,7 @@ const AnimatedButton = ({
}

return href ? (
<SeoLink to={href} {...rootProps}>
<SeoLink to={href} {...rootProps} {...buttonProps}>
{buttonElement}
</SeoLink>
) : (
Expand Down
5 changes: 5 additions & 0 deletions packages/web/src/components/bottom-bar/BottomBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,23 @@ const BottomBar = ({
onClick={onClick(onClickFeed, FEED_PAGE)}
href={FEED_PAGE}
isMatrixMode={isMatrixMode}
aria-label='Feed Page'
/>
<TrendingButton
isActive={tempCurrentPage === TRENDING_PAGE}
darkMode={isDarkMode}
onClick={onClick(onClickTrending, TRENDING_PAGE)}
href={TRENDING_PAGE}
isMatrixMode={isMatrixMode}
aria-label='Trending Page'
/>
<ExploreButton
isActive={tempCurrentPage === EXPLORE_PAGE}
darkMode={isDarkMode}
onClick={onClick(onClickExplore, EXPLORE_PAGE)}
href={EXPLORE_PAGE}
isMatrixMode={isMatrixMode}
aria-label='Explore Page'
/>
<LibraryButton
isActive={
Expand All @@ -97,13 +100,15 @@ const BottomBar = ({
onClick={onClick(onClickLibrary, LIBRARY_PAGE)}
href={LIBRARY_PAGE}
isMatrixMode={isMatrixMode}
aria-label='Library Page'
/>
<ProfileButton
isActive={tempCurrentPage === userProfilePageRoute}
darkMode={isDarkMode}
onClick={onClick(onClickProfile, userProfilePageRoute)}
href={userProfilePageRoute || undefined}
isMatrixMode={isMatrixMode}
aria-label='Profile Page'
/>
</div>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const ExploreButton = ({
onClick,
href,
isActive,
isMatrixMode
isMatrixMode,
...buttonProps
}: ButtonProps) => {
return (
<AnimatedBottomButton
Expand All @@ -24,6 +25,7 @@ const ExploreButton = ({
iconDarkJSON={() =>
import('../../../assets/animations/iconExploreDark.json')
}
{...buttonProps}
/>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const FeedButton = ({
onClick,
href,
isActive,
isMatrixMode
isMatrixMode,
...buttonProps
}: ButtonProps) => {
return (
<AnimatedBottomButton
Expand All @@ -24,6 +25,7 @@ const FeedButton = ({
iconDarkJSON={() =>
import('../../../assets/animations/iconFeedDark.json')
}
{...buttonProps}
/>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const LibraryButton = ({
onClick,
href,
isActive,
isMatrixMode
isMatrixMode,
...buttonProps
}: ButtonProps) => {
return (
<AnimatedBottomButton
Expand All @@ -24,6 +25,7 @@ const LibraryButton = ({
iconDarkJSON={() =>
import('../../../assets/animations/iconFavoriteDark.json')
}
{...buttonProps}
/>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const ProfileButton = ({
onClick,
href,
isActive,
isMatrixMode
isMatrixMode,
...buttonProps
}: ButtonProps) => {
return (
<AnimatedBottomButton
Expand All @@ -18,12 +19,14 @@ const ProfileButton = ({
isMatrix={isMatrixMode}
onClick={onClick}
href={href}
aria-label='Profile Page'
iconLightJSON={() =>
import('../../../assets/animations/iconProfileLight.json')
}
iconDarkJSON={() =>
import('../../../assets/animations/iconProfileDark.json')
}
{...buttonProps}
/>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const TrendingButton = ({
onClick,
href,
isActive,
isMatrixMode
isMatrixMode,
...buttonProps
}: ButtonProps) => {
return (
<AnimatedBottomButton
Expand All @@ -24,6 +25,7 @@ const TrendingButton = ({
iconDarkJSON={() =>
import('../../../assets/animations/iconTrendingDark.json')
}
{...buttonProps}
/>
)
}
Expand Down
30 changes: 9 additions & 21 deletions packages/web/src/components/drawer/Drawer.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import {
useEffect,
useCallback,
useRef,
ReactNode,
useState,
RefObject
} from 'react'
import { useEffect, useCallback, useRef, ReactNode, useState } from 'react'

import { useInstanceVar } from '@audius/common/hooks'
import { IconClose } from '@audius/harmony'
import { disableBodyScroll, clearAllBodyScrollLocks } from 'body-scroll-lock'
import cn from 'classnames'
// eslint-disable-next-line no-restricted-imports -- TODO: migrate to @react-spring/web
import { useSpring, animated, useTransition } from 'react-spring'
import { useMeasure } from 'react-use'
import { useDrag } from 'react-use-gesture'

import { usePortal } from 'hooks/usePortal'
Expand Down Expand Up @@ -65,12 +59,6 @@ export type DrawerProps = {
'aria-labelledby'?: string
}

const getHeight = (contentRef: RefObject<HTMLDivElement>) => {
if (!contentRef.current) return 0

return contentRef.current.getBoundingClientRect().height
}

const DraggableDrawer = ({
isOpen,
children,
Expand All @@ -81,18 +69,18 @@ const DraggableDrawer = ({
}: DrawerProps) => {
const Portal = usePortal({})

const contentRef = useRef<HTMLDivElement>(null)

// Stores the initial translation of the drawer
const [initialTranslation] = useInstanceVar(0)
// Stores the last transition
const [currentTranslation, setCurrentTranslation] = useInstanceVar(0)
// isBackgroundVisible will be true until the close animation finishes
const [isBackgroundVisible, setIsBackgroundVisible] = useState(false)

const [contentRef, { height: contentHeight }] = useMeasure<HTMLDivElement>()

const [drawerSlideProps, setDrawerSlideProps] = useSpring(() => ({
to: {
y: -1 * getHeight(contentRef)
y: -1 * contentHeight
},
config: wobble,
onFrame(frame: any) {
Expand All @@ -118,7 +106,7 @@ const DraggableDrawer = ({
setIsBackgroundVisible(true)
setDrawerSlideProps({
to: {
y: -1 * getHeight(contentRef)
y: -1 * contentHeight
},
immediate: false,
config: wobble,
Expand All @@ -140,9 +128,9 @@ const DraggableDrawer = ({
})
}, [
setDrawerSlideProps,
contentHeight,
setContentFadeProps,
setBackgroundOpacityProps,
setIsBackgroundVisible
setBackgroundOpacityProps
])

const close = useCallback(() => {
Expand Down Expand Up @@ -199,7 +187,7 @@ const DraggableDrawer = ({
movement: [, my],
memo = currentTranslation()
}) => {
const height = getHeight(contentRef)
const height = contentHeight

let newY = memo + my

Expand Down
2 changes: 2 additions & 0 deletions packages/web/src/components/nav/desktop/NavHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ export const NavHeader = () => {
[styles.active]: notificationCount > 0,
[styles.notificationsOpen]: notificationPanelIsOpen
})}
role='button'
aria-label='Open notifications menu'
>
<IconNotification />
</div>
Expand Down
3 changes: 3 additions & 0 deletions packages/web/src/components/nav/desktop/NavPopupMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ const NavPopupMenu = () => {
className={styles.icon}
ref={anchorRef}
onClick={() => triggerPopup()}
role='button'
aria-label='Open settings menu'
>
<IconKebabHorizontal size='s' />
</div>
Expand All @@ -167,6 +169,7 @@ const NavPopupMenu = () => {
)
}}
zIndex={zIndex.NAVIGATOR_POPUP}
aria-label='Open settings menu'
/>
</div>
)
Expand Down
7 changes: 6 additions & 1 deletion packages/web/src/pages/sign-in-page/SignInPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,12 @@ export const SignInPage = () => {
</Flex>
</Flex>
{!isMobile ? (
<Button variant='secondary' asChild fullWidth>
<Button
variant='secondary'
asChild
fullWidth
style={{ flexShrink: 0 }}
>
<Link to={SIGN_UP_PAGE}>{signInPageMessages.createAccount}</Link>
</Button>
) : null}
Expand Down

0 comments on commit 0c8911a

Please sign in to comment.