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

[UI Framework] KuiGalleryItem automatically becomes link or button #14240

Merged
merged 4 commits into from Oct 12, 2017

Conversation

timroes
Copy link
Contributor

@timroes timroes commented Oct 2, 2017

As discussed with @cjcenizal introducing with this PR the KuiGalleryItem will now automatically decide whether it needs to be an a or a button element.

If an href property is specified it will become an a element, otherwise it will become a button. An prop type error is thrown when both properties are specified.

This is mainly done for accessibility reasons, so that keyboard accessibility will work properly in all circumstances.

@timroes timroes added Team:Platform-Design Team Label for Kibana Design Team. Support the Analyze group of plugins. review v6.1.0 v7.0.0 labels Oct 2, 2017
@timroes timroes requested a review from aphelionz October 2, 2017 14:04
@@ -2,18 +2,41 @@ import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

export const KuiGalleryItem = ({ children, className, ...rest }) => {
const checkHrefAndOnClick = (props, propName, componentName) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice. I should add this to K7 stuff too. I wasn't this detailed to check for both.

Copy link
Contributor

@cjcenizal cjcenizal left a comment

Choose a reason for hiding this comment

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

Looking good! Just had one suggestion.

const component = <KuiGalleryItem href="#" {...requiredProps}>children</KuiGalleryItem>;
expect(render(component)).toMatchSnapshot();
});

test('renders KuiGalleryItem with onClick', () => {
const component = <KuiGalleryItem onClick={() => {}} {...requiredProps}>children</KuiGalleryItem>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of doing a snapshot comparison, we should test that the callback is called when the element is clicked, similar to how our KuiButton tests work:

    describe('onClick', () => {
      test(`isn't called upon instantiation`, () => {
        const onClickHandler = sinon.stub();

        shallow(
          <KuiButton onClick={onClickHandler} />
        );

        sinon.assert.notCalled(onClickHandler);
      });

      test('is called when the button is clicked', () => {
        const onClickHandler = sinon.stub();

        const $button = shallow(
          <KuiButton onClick={onClickHandler} />
        );

        $button.simulate('click');

        sinon.assert.calledOnce(onClickHandler);
      });
    });

Could you also add an example of a KuiGalleryItem using onClick in the doc site and verify that it gets applied and called when you click?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@timroes
Copy link
Contributor Author

timroes commented Oct 10, 2017

@cjcenizal could you give it another look?

Copy link
Contributor

@cjcenizal cjcenizal left a comment

Choose a reason for hiding this comment

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

@timroes Thanks for the ping, sorry about the delay! Could you also add an example of a KuiGalleryItem using onClick in the doc site and verify that it gets applied and called when you click, e.g. by making the handler call window.alert? After that this LGTM!

@timroes
Copy link
Contributor Author

timroes commented Oct 11, 2017

Thanks for the feedback. Could you give it one last look with the doc, then I would merge it :-)

Copy link
Contributor

@cjcenizal cjcenizal left a comment

Choose a reason for hiding this comment

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

LGTM!

@timroes timroes merged commit ced8d97 into elastic:master Oct 12, 2017
@timroes timroes deleted the kui-gallery-item-html branch October 12, 2017 08:22
timroes added a commit that referenced this pull request Oct 12, 2017
…14240)

* KuiGalleryItem automatically becomes link or button

* Add onClick tests

* Add doc example with onClick
@timroes
Copy link
Contributor Author

timroes commented Oct 12, 2017

Backports:

@timroes timroes removed the review label Nov 17, 2017
chrisronline pushed a commit to chrisronline/kibana that referenced this pull request Nov 20, 2017
…lastic#14240)

* KuiGalleryItem automatically becomes link or button

* Add onClick tests

* Add doc example with onClick
chrisronline pushed a commit to chrisronline/kibana that referenced this pull request Dec 1, 2017
…lastic#14240)

* KuiGalleryItem automatically becomes link or button

* Add onClick tests

* Add doc example with onClick
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:enhancement Team:Platform-Design Team Label for Kibana Design Team. Support the Analyze group of plugins. v6.1.0 v7.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants