-
Notifications
You must be signed in to change notification settings - Fork 53
feat(bindings): add useAccessibility hook #1980
Conversation
type UseAccessibilityOptions<Props> = { | ||
actionHandlers?: AccessibilityActionHandlers | ||
debugName?: string | ||
mapPropsToBehavior?: () => Props |
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.
can this be Props | () => Props
for API simplification? looking at the unit tests I think passing an object there should be sufficient for most use cases.
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.
I see that you mean, but I want to keep it obvious for now and in sync with useStateManager()
. We can improve this part once we will receive feedback for this thing.
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.
I agree that Props | () => Props
maybe make sense, in most of the cases I see this as a simple props mapping.. Anyways, not a blocker :)
50e922c
to
6eaee19
Compare
fec7a66
to
ffbd363
Compare
ffbd363
to
e7d88da
Compare
e7d88da
to
48d50c0
Compare
48d50c0
to
70f3229
Compare
@@ -1,6 +1,6 @@ | |||
import { KeyCombinations } from '@stardust-ui/accessibility' | |||
// @ts-ignore |
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.
There are no typings for keyboard-key
π
Co-Authored-By: Marija Najdova <[email protected]>
β¦b.com/stardust-ui/react into feat/use-accessibility # Conflicts: # packages/react/src/lib/renderComponent.tsx
β¦b.com/stardust-ui/react into feat/use-accessibility # Conflicts: # packages/accessibility/src/types.ts # packages/react-bindings/src/accessibility/shouldHandleOnKeys.ts # packages/react/src/components/Menu/Menu.tsx # packages/react/src/components/Popup/Popup.tsx # packages/react/src/components/Portal/Portal.tsx # packages/react/src/components/Tooltip/Tooltip.tsx # packages/react/src/components/Tree/Tree.tsx # packages/react/src/components/Tree/TreeItem.tsx # packages/react/src/lib/getKeyDownHandlers.ts # packages/react/src/lib/renderComponent.tsx
Hi, just a heads up that I made a change #2153 renaming all |
β¦b.com/stardust-ui/react into feat/use-accessibility
β¦b.com/stardust-ui/react into feat/use-accessibility # Conflicts: # packages/react/src/components/Tooltip/Tooltip.tsx # packages/react/src/utils/createComponent.tsx # packages/react/src/utils/factories.ts
β¦b.com/stardust-ui/react into feat/use-accessibility
@@ -321,7 +217,32 @@ const renderComponent = <P extends {}>( | |||
} | |||
} | |||
|
|||
return result | |||
if (accessibility.focusZone && accessibility.focusZone.mode === FocusZoneMode.Wrap) { |
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.
Can we extract this in a separate function
|
||
if (slotHandlers) { | ||
const onKeyDown = (e: React.KeyboardEvent, ...args: any[]) => { | ||
const keyHandlers = definition.keyHandlers[slotName] |
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.
const keyHandlers = definition.keyHandlers[slotName] | |
const keyHandlers = slotHandlers |
Points of confusion / Parts that were blamed
|
β¦at/use-accessibility
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.
We reviewed and agreed that there are parts that can be improved (see #1980 (comment)), but it can be merged as is now, and we'll iterate later on them. Good job @layershifter!
π΄
useAccessibility()
This PR adds support for
useAccessibility()
hook that allows to use existing or created behavior in custom components.π¨βπ» Example
mapPropsToBehavior()
- passesprops
to behavior, allows to pass props strictly, similar tomapPropsToState()
inuseStateManager()
actionHandlers
- works as existingactionHandlers
in our components and allows to bind component actions to actions described in behaviorsgetA11Props(slotName, slotProps)
- a function that applies accessibility props and performs proper merge with user's propsπ‘ POC
https://codesandbox.io/s/dropdown-prototype-r3ux9
(prototype of
Dropdown
component that usesuseStateManager()
anduseAccessibility()
)Questions
1οΈβ£ Refactor to
.root()
syntaxDuring our discussion @levithomason, he proposed more fancy signature for
getA11Props()
:Key issue with this proposal that I don't understand there is Π΅ΡΡ replacement of behaviors. For example, I can replace
imageBehavior
withemptyBehavior
without definitions for any slots. How I will not that I need to create agetA11Props.image()
?As solution, I can use
Proxy
, but it's not supported in IE11 π£2οΈβ£
FocusZone
There is no support in
useAccessibility()
forFocusZone
, I propose to ship it later. Now, I am not fully sure around approaches and want to discuss them separately.