feat(Popup): refactor and add controlled mode#282
Conversation
Codecov Report
@@ Coverage Diff @@
## master #282 +/- ##
========================================
- Coverage 91.69% 89.9% -1.8%
========================================
Files 62 62
Lines 1168 1159 -9
Branches 150 150
========================================
- Hits 1071 1042 -29
- Misses 94 115 +21
+ Partials 3 2 -1
Continue to review full report at Codecov.
|
| import React from 'react' | ||
| import { Button, Grid, Popup } from '@stardust-ui/react' | ||
|
|
||
| class PopupArrowExample extends React.Component<any, any> { |
There was a problem hiding this comment.
why the name is PopupArrow? :)
There was a problem hiding this comment.
+1 name should reflect name of file
src/components/Popup/Popup.tsx
Outdated
|
|
||
| /** The popup content (deprecated). */ | ||
| children: customPropTypes.disallow(['children']), | ||
| children: PropTypes.any, // customPropTypes.disallow(['children']), |
There was a problem hiding this comment.
to remove disallow statement - yes, this is intended :) but at the same time (other than cleaning up commented code), PropTypes.node would be a better substitute here - let me address that.
There was a problem hiding this comment.
why do we remove it? we support children API now?
There was a problem hiding this comment.
yes - as this is quite reasonable for the Popup case, see:
<SomeTree>
<Popup content={popupContent}>
<button>Click me to trigger popup</button>
</Popup>
</SomeTree>Now to introduce popup functionality it is necessary just to wrap the component that previously was in the tree - to augment it with popup functionality (and make it a trigger)
src/components/Popup/Popup.tsx
Outdated
| toggle: e => _.invoke(this.props, 'onOpenChange', e, !this.props.open), | ||
| closeAndFocusTrigger: e => { | ||
| _.invoke(this.props, 'onOpenChange', false) | ||
| _.invoke(this.state.triggerRef, 'focus') |
There was a problem hiding this comment.
So, in case of user won't provide onOpenChange function which will handle open/close state, the Popup won't be closed, but the trigger would be focused. It seems like a not expected scenario.
And seems like same for toggle (in case it's not a button).
Let's discuss it.
There was a problem hiding this comment.
this is a good catch - lets discuss closeAndFocus case. Speaking of the toggle one - could you, please, suggest what the problem is exactly about?
There was a problem hiding this comment.
Speaking of a toggle, if a trigger is not button element, you won't be able to toggle popup with Enter\ Space button. So, do we expect here that a user should use ```onOpenChange`` function in case to handle toggling?
There was a problem hiding this comment.
yes - but this leads us to more general problem that is rather accessibility related. In this PR I would like to focus on the following things, with all the previously introduced functionality being untouched:
- refactor and simplify
Popupbase implementation - introduce controlled mode to it
So, these are the main reasons I've left PopupBehavior's functionality as it was introduced before. so that If we would like to address/discuss some problems related to this aspect exclusively, we would be able to do it by means of a dedicated PR.
Please, let me know about your thoughts on that :)
docs/src/examples/components/Popup/Variations/PopupExamplePosition.shorthand.tsx
Show resolved
Hide resolved
src/components/Popup/Popup.tsx
Outdated
| content?: ItemShorthand | ItemShorthand[] | ||
| defaultOpen?: boolean | ||
| open?: boolean | ||
| onOpenChange?: () => void |
There was a problem hiding this comment.
should't we expose the open flag here as well; what's the advantage of this on having 2 props as in SUIR:
onOpen and onClose?
There was a problem hiding this comment.
+1 for adding handlers onOpen and onClose that would be invoked based on the value of the open. It is much cleaner API for the user.
src/components/Popup/Popup.tsx
Outdated
| ...accessibility.keyHandlers.trigger, | ||
| })} | ||
| </Ref> | ||
| {this.props.open && this.renderPopupContent(rtl, accessibility)} |
There was a problem hiding this comment.
nit: add open to destructured object above and use from there
docs/src/examples/components/Popup/Variations/PopupExamplePosition.shorthand.tsx
Show resolved
Hide resolved
docs/src/examples/components/Popup/Variations/PopupExamplePosition.shorthand.tsx
Show resolved
Hide resolved
docs/src/examples/components/Popup/Variations/PopupExamplePosition.shorthand.tsx
Outdated
Show resolved
Hide resolved
docs/src/examples/components/Popup/Variations/PopupExamplePosition.shorthand.tsx
Show resolved
Hide resolved
docs/src/examples/components/Popup/Variations/PopupExamplePosition.shorthand.tsx
Show resolved
Hide resolved
bmdalex
left a comment
There was a problem hiding this comment.
pls take a look at comments
src/components/Popup/Popup.tsx
Outdated
| style={popupPlacementStyles} | ||
| {...accessibility.attributes.popup} | ||
| {...accessibility.keyHandlers.popup} | ||
| data-placement={placement} |
There was a problem hiding this comment.
why is this needed? accessibility / w3c standards? it's not adding any functionality
There was a problem hiding this comment.
these lines reflect changes that were merged by another PR - please, take a look on the current state of master. So, those are necessary to project this already introduced functionality on top of changes made in this PR
There was a problem hiding this comment.
I was talking about line 162:
data-placement={placement}There was a problem hiding this comment.
oh, got it - let me address..
| { position: 'after', align: 'bottom', icon: 'arrow circle right', padding: '18px 5px 5px 42px' }, | ||
| ] | ||
|
|
||
| const PopupExamplePosition = () => ( |
There was a problem hiding this comment.
This const and the class both have the same name which is casing some compiler errors:
[at-loader] Checking finished with 2 errors
[at-loader] ./docs/src/examples/components/Popup/Variations/PopupExamplePosition.shorthand.tsx:4:7
TS2300: Duplicate identifier 'PopupExamplePosition'.
[at-loader] ./docs/src/examples/components/Popup/Variations/PopupExamplePosition.shorthand.tsx:52:7
TS2300: Duplicate identifier 'PopupExamplePosition'.
Please rename one of them.

TODO
The following issues are aimed to be addressed by the proposed PR:
Popupcomponentaspropascomponents/elements could cause breaks in ref capturing logicPopupopenanddefaultOpenprops