-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
feat(Popup): Multiple event triggering a Popup #1977
Conversation
The position of the Popup on elements with smaller width(<25px) not aligned.
Popup triggering by multiple events(hover, focus or click)
Codecov Report
@@ Coverage Diff @@
## master #1977 +/- ##
=========================================
+ Coverage 99.8% 99.8% +<.01%
=========================================
Files 148 148
Lines 2568 2569 +1
=========================================
+ Hits 2563 2564 +1
Misses 5 5
Continue to review full report at Codecov.
|
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.
@vipul-21 Thanks for PR! But we can't merge it as is because it will introduce a breaking change. However, we can easily omit it, let's use normalization of on
, this will allow to left compability with current API.
src/modules/Popup/Popup.js
Outdated
@@ -250,15 +250,16 @@ export default class Popup extends Component { | |||
portalProps.closeOnPortalMouseLeave = true | |||
portalProps.mouseLeaveDelay = 300 | |||
} | |||
|
|||
if (on === 'click') { | |||
if (_.indexOf(on, 'click') > -1) { |
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.
_.includes
can be used there
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 can normalize value there and then use it:
const normalizedOn = _.isArray(on) ? on : [on]
This will allow to pass on='hover'
and on={['hover']}
src/modules/Popup/Popup.js
Outdated
@@ -127,7 +127,7 @@ export default class Popup extends Component { | |||
|
|||
static defaultProps = { | |||
position: 'top left', | |||
on: 'hover', | |||
on: ['hover'], |
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 can left this
src/modules/Popup/Popup.js
Outdated
@@ -72,7 +72,7 @@ export default class Popup extends Component { | |||
offset: PropTypes.number, | |||
|
|||
/** Event triggering the popup. */ | |||
on: PropTypes.oneOf(['hover', 'click', 'focus']), | |||
on: PropTypes.arrayOf(PropTypes.oneOf(['hover', 'click', 'focus'])), |
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.
Valid propType will be:
propTypes.oneOfType([
PropTypes.oneOf(['hover', 'click', 'focus']),
PropTypes.arrayOf(['hover', 'click', 'focus']),
])
src/modules/Popup/Popup.d.ts
Outdated
@@ -39,7 +39,7 @@ export interface PopupProps extends PortalProps { | |||
offset?: number; | |||
|
|||
/** Event triggering the popup. */ | |||
on?: 'hover' | 'click' | 'focus'; | |||
on?: Array<string>; |
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.
'hover' | 'click' | 'focus' | Array<'hover' | 'click' | 'focus'>
This should be correct as I remember
@@ -5,7 +5,7 @@ const PopupExampleClick = () => ( | |||
<Popup | |||
trigger={<Button color='red' icon='flask' content='Activate doomsday device' />} | |||
content={<Button color='green' content='Confirm the launch' />} | |||
on='click' | |||
on={['click']} |
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.
Let's revert this
@layershifter I have updated the changes as recommended. But the array being assigned to |
@@ -5,7 +5,7 @@ const PopupExampleClick = () => ( | |||
<Popup | |||
trigger={<Button color='red' icon='flask' content='Activate doomsday device' />} | |||
content={<Button color='green' content='Confirm the launch' />} | |||
on='click' | |||
on={'click'} |
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.
Just on='click'
, please
@@ -26,7 +26,7 @@ class PopupExampleControlled extends React.Component { | |||
<Popup | |||
trigger={<Button content='Open controlled popup' />} | |||
content={`This message will self-destruct in ${timeoutLength / 1000} seconds!`} | |||
on='click' | |||
on={'click'} |
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.
^
@@ -6,7 +6,7 @@ const PopupExampleFocus = () => ( | |||
trigger={<Input icon='search' placeholder='Search...' />} | |||
header='Movie Search' | |||
content='You may search by genre, header, year and actors' | |||
on='focus' | |||
on={'focus'} |
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.
^
You're right, |
@vipul-21 Thanks for changes, we need only to add test describe('trigger', () => {
// .....
it('it appears on multiple', (done) => {
const trigger = <button>foo</button>
const button = wrapperMount(<Popup on={['click', 'hover']} content='foo' header='bar' trigger={trigger} />)
.find('button')
button.simulate('click')
assertInBody('.ui.popup.visible')
domEvent.click('body')
button.simulate('mouseenter')
setTimeout(() => {
assertInBody('.ui.popup.visible')
done()
}, 51)
})
}) |
Very cool, thanks |
Released in |
Popup triggering by multiple events(hover, focus or click)