Skip to content
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

Merged
merged 9 commits into from
Aug 20, 2017

Conversation

vipul-21
Copy link
Contributor

Popup triggering by multiple events(hover, focus or click)

vipul added 4 commits August 16, 2017 20:15
The position of the Popup on elements with smaller width(<25px) not aligned.
Popup triggering by multiple events(hover, focus or click)
@codecov-io
Copy link

codecov-io commented Aug 17, 2017

Codecov Report

Merging #1977 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #1977      +/-   ##
=========================================
+ Coverage    99.8%   99.8%   +<.01%     
=========================================
  Files         148     148              
  Lines        2568    2569       +1     
=========================================
+ Hits         2563    2564       +1     
  Misses          5       5
Impacted Files Coverage Δ
src/modules/Popup/Popup.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a4780cd...1354c3b. Read the comment docs.

Copy link
Member

@layershifter layershifter left a 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.

@@ -250,15 +250,16 @@ export default class Popup extends Component {
portalProps.closeOnPortalMouseLeave = true
portalProps.mouseLeaveDelay = 300
}

if (on === 'click') {
if (_.indexOf(on, 'click') > -1) {
Copy link
Member

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

Copy link
Member

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']}

@@ -127,7 +127,7 @@ export default class Popup extends Component {

static defaultProps = {
position: 'top left',
on: 'hover',
on: ['hover'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can left this

@@ -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'])),
Copy link
Member

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']), 
])

@@ -39,7 +39,7 @@ export interface PopupProps extends PortalProps {
offset?: number;

/** Event triggering the popup. */
on?: 'hover' | 'click' | 'focus';
on?: Array<string>;
Copy link
Member

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']}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's revert this

@vipul-21
Copy link
Contributor Author

vipul-21 commented Aug 18, 2017

@layershifter I have updated the changes as recommended. But the array being assigned to on is giving a type error. I am not able to figure out why. Can you help me out ?

@@ -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'}
Copy link
Member

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'}
Copy link
Member

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'}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^

@layershifter
Copy link
Member

layershifter commented Aug 18, 2017

You're right, PropTypes.arrayOf accepts type, not value, so correct propType will be PropTypes.arrayOf(PropTypes.oneOf(['hover', 'click', 'focus'])),

@layershifter
Copy link
Member

@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)
    })
  })

@levithomason levithomason merged commit 87bae70 into Semantic-Org:master Aug 20, 2017
@levithomason
Copy link
Member

Very cool, thanks

@levithomason
Copy link
Member

Released in semantic-ui-react@0.71.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants