-
Notifications
You must be signed in to change notification settings - Fork 61
feat: Add reduce motion support to <Tray>
#386
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
Changes from all commits
7255d3f
e448ffb
a015eff
b86e72e
980adf4
1bc147a
e875f92
74da0d1
8bb6e09
3263154
2a4a968
fe9f2e3
34a87c4
5b98135
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -370,8 +370,33 @@ function PreventDismissTray() { | |
|
|
||
| ## Accessibility | ||
|
|
||
| ### Accessibility labels | ||
|
|
||
| Trays require an accessibility label. If you pass in a ReactNode to `title`, make sure to set `accessibilityLabel`. | ||
|
|
||
| ### Reduce Motion | ||
|
|
||
| Use the `reduceMotion` prop to accommodate users with reduced motion settings. | ||
|
|
||
| ```jsx | ||
| function ReducedMotionTray() { | ||
| const [visible, setVisible] = useState(false); | ||
| const handleOpen = () => setVisible(true); | ||
| const handleClose = () => setVisible(false); | ||
|
|
||
| return ( | ||
| <VStack gap={2}> | ||
| <Button onPress={handleOpen}>Open Tray</Button> | ||
| {visible && ( | ||
| <Tray reduceMotion onCloseComplete={handleClose} title="Reduced Motion"> | ||
| <Text color="fgMuted">This tray fades in and out using opacity.</Text> | ||
| </Tray> | ||
| )} | ||
| </VStack> | ||
| ); | ||
| } | ||
| ``` | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we have this example match our others, maybe the basic one? Such as
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated the example and updated the behavior of web Tray to prevent dragging behavior when |
||
|
|
||
| ## Styling | ||
|
|
||
| ### Handlebar | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import React from 'react'; | ||
|
|
||
| import { Example, ExampleScreen } from '../../examples/ExampleScreen'; | ||
|
|
||
| import { DefaultDrawer } from './Drawers'; | ||
|
|
||
| const DrawerReduceMotionScreen = () => { | ||
| return ( | ||
| <ExampleScreen> | ||
| <Example title="Reduce Motion Drawer"> | ||
| <DefaultDrawer reduceMotion pin="bottom" /> | ||
| </Example> | ||
| </ExampleScreen> | ||
| ); | ||
| }; | ||
|
|
||
| export default DrawerReduceMotionScreen; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import React, { useCallback, useRef, useState } from 'react'; | ||
|
|
||
| import { Button } from '../../buttons/Button'; | ||
| import { Example, ExampleScreen } from '../../examples/ExampleScreen'; | ||
| import { VStack } from '../../layout'; | ||
| import { Text } from '../../typography/Text'; | ||
| import type { DrawerRefBaseProps } from '../drawer/Drawer'; | ||
| import { Tray } from '../tray/Tray'; | ||
|
|
||
| export const TrayReduceMotionScreen = () => { | ||
| return ( | ||
| <ExampleScreen> | ||
| <Example title="Reduce Motion Tray"> | ||
| <TrayWithReduceMotion /> | ||
| </Example> | ||
| </ExampleScreen> | ||
| ); | ||
| }; | ||
|
|
||
| const TrayWithReduceMotion = () => { | ||
| const [isTrayVisible, setIsTrayVisible] = useState(false); | ||
| const setIsTrayVisibleOff = useCallback(() => setIsTrayVisible(false), [setIsTrayVisible]); | ||
| const setIsTrayVisibleOn = useCallback(() => setIsTrayVisible(true), [setIsTrayVisible]); | ||
| const trayRef = useRef<DrawerRefBaseProps>(null); | ||
|
|
||
| const handleTrayVisibilityChange = useCallback((e: 'visible' | 'hidden') => { | ||
| console.log('Tray visibility changed:', e); | ||
| }, []); | ||
|
|
||
| return ( | ||
| <> | ||
| <Button onPress={setIsTrayVisibleOn}>Open</Button> | ||
| {isTrayVisible && ( | ||
| <Tray | ||
| ref={trayRef} | ||
| reduceMotion | ||
| handleBarVariant="inside" | ||
| onCloseComplete={setIsTrayVisibleOff} | ||
| onVisibilityChange={handleTrayVisibilityChange} | ||
| title="Header" | ||
| > | ||
| <VStack paddingX={3}> | ||
| <Text font="body"> | ||
| Curabitur commodo nulla vel dolor vulputate vestibulum. Nulla et nisl molestie, | ||
| interdum lorem id, viverra. | ||
| </Text> | ||
| </VStack> | ||
| </Tray> | ||
| )} | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| export default TrayReduceMotionScreen; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did we have customers request this prop? I do worry until we refresh motion and have built in support for reduced motion this will either not get used or will not be used consistently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It wasn't a customer request. It was discussed at our last onsite and this would be a meaningful addition for accessibility!
Regarding your concern for if this will be used: it's a good point to raise! In this PR there are docs site examples to call out the prop. Beyond that, I'm not sure how else we could enforce the usage of this prop.
This is more of a temporary solution since we should be offering this already. The current plan for our motion rework includes supporting animation configuration at the prop level. So this type of logic (determining animation based on props) will still exist after.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha, makes sense!