feat(Accessibility): Add accessibility behavior to Popup#218
feat(Accessibility): Add accessibility behavior to Popup#218
Conversation
Codecov Report
@@ Coverage Diff @@
## master #218 +/- ##
=========================================
- Coverage 92.44% 91.8% -0.64%
=========================================
Files 63 63
Lines 1151 1171 +20
Branches 151 173 +22
=========================================
+ Hits 1064 1075 +11
- Misses 84 92 +8
- Partials 3 4 +1
Continue to review full report at Codecov.
|
kuzhelov
left a comment
There was a problem hiding this comment.
great improvement - lets address (discuss) the problem related to triggerAccessibility object's type, and it seems that we would be good to go :)
src/components/Portal/Portal.tsx
Outdated
| {React.cloneElement(trigger, { onClick: this.handleTriggerClick })} | ||
| {React.cloneElement(trigger, { | ||
| onClick: this.handleTriggerClick, | ||
| ...triggerAccessibility, |
There was a problem hiding this comment.
another related problem (to the fact that there is no enforcement over the triggerAccessibility type on the client-code side) is that currently it is very easy to accidentally do things wrong: it is sufficient to add any property to triggerAccessibility object that cannot be properly expanded to element's attributes to break the entire app. For the sake of argument, you could try the following for Popup.tsx (it won't be caught by the compiler now):
return (
<ElementType
...
triggerAccessibility={{
...accessibility.attributes.trigger,
...accessibility.keyHandlers.trigger,
someFoo: { bar: true }
}}
...I would really suggest to introduce some type to restrict the set of possible values, and use it on the client side as well - the least we can do for now:
// in Popup
return (
<ElementType
...
triggerAccessibility={{
...accessibility.attributes.trigger,
...accessibility.keyHandlers.trigger,
} as TriggerAccessibility}// in types declaration
type TriggerAccessibility = IAccessibilityAttributes & OnKeyDownHandler // or better { attributes: ..., handlers: ...}There was a problem hiding this comment.
I'll make this type
type TriggerAccessibility = {
attributes?: IAccessibilityAttributes
keyHandlers?: OnKeyDownHandler
}
|
@kuzhelov Thank you for your review! Made changes regarding |
src/components/Popup/Popup.tsx
Outdated
| triggerAccessibility={{ | ||
| attributes: accessibility.attributes.trigger, | ||
| keyHandlers: accessibility.keyHandlers.trigger, | ||
| }} |
There was a problem hiding this comment.
lets, please, make explicit as cast here (and use TriggerAccessibility type) - this will ensure that it would be hard to accidentally break the app with new props being added to either attributes or handlers
There was a problem hiding this comment.
lets, please, ensure that it would be hard to break the app with new property being added to either attributes or keyHandlers part of the triggerAccessibility object - have left a comment. Other than that we are good to merge 👍
Also, please, do not forget to mention the changes made in the CHANGELOG file.
This PR aims to make popup accessible, by adding
PopupBehaviorto thePopupcomponent.For accessibility purpose, we should be able to manage
open/closestate of the Portal from Popup component. So in th PR I've addedpopupStateto the Popup which controllsopenprop of the Portal.PopupBehaviordetails:aria-* attributes- popup's trigger will receive attributes like 'aria-haspopup'keyActions- for the
triggercomponent's part -performClick(onEnter&Space), which currently will toggle open/close state)- for
popupcomponent's part -closeAndFocusTrigger- when user pressesEscon a popup, it will be closed and the trigger node will be focusedExtended
Portal's APItriggerAccessibility- receives accessibility related attributes, likeonOutsideClick- callback whick can be invoked when document was clicked outside of trigger and popup nodesonTriggerClick- since it's needed to controlopenstate from popup, we have to handle trigger click in a popup tooSuggestion, probably for future:
onOpen,onClose, so users can controll what should be done before opening and closing a popup, for e.g. managing focus