Skip to content

Add FieldLevelHelp component - #179

Merged
jeff-phillips-18 merged 16 commits into
patternfly:masterfrom
AparnaKarve:add_fieldlevelhelp_component
Feb 6, 2018
Merged

jeff-phillips-18 merged 16 commits into
patternfly:masterfrom
AparnaKarve:add_fieldlevelhelp_component

Conversation

@AparnaKarve

@AparnaKarve AparnaKarve commented Jan 23, 2018 •

Copy link
Copy Markdown
Contributor

Added a new component called FieldLevelHelp based on the design requirements in http://www.patternfly.org/pattern-library/forms-and-controls/help-on-forms/

FieldLevelHelp Storybook

Fixes #115

@serenamarie125

Copy link
Copy Markdown
Member

@AparnaKarve glad to see your first contribution here!

@serenamarie125 serenamarie125 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@AparnaKarve couple comments re: UX review

#1 - can you change the placement of the popover so it "points" at the "I" icon as shown here in the design: http://www.patternfly.org/pattern-library/forms-and-controls/help-on-forms/#design

#2 - per the design, I think we only support with popover, not tooltip - @jgiardino what do you think? should we remove the tooltip option to be inline with the documentation and ensure consistency?

#3 - this is a nit, but wondering if you could change the example to bring up a new tab when the link in the popover is clicked ? That would be the desired behavior, so if it's easy to change it may be worth it

@jeff-phillips-18

Copy link
Copy Markdown
Member

Adding an action log for the link might be a better choice than adding a tab. Just my $00.02

>
<label>
{children + ' '}
<Icon type="pf" name={'info'} style={{ color: '#0088ce' }} />

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we shouldn't use an inline style here add the btn-link class instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

btn-link introduces an underline that we typically see for links on a mouse hover, as shown below -
screen shot 2018-01-24 at 11 29 32 am

Is there a way to remove that?

@dabeng

dabeng commented Jan 24, 2018

Copy link
Copy Markdown
Contributor

Hi @AparnaKarve , It will be better if you enable KNOBS panel to change "placement" or "trigger" properties 😊

@ohadlevy

Copy link
Copy Markdown
Member

and please add tests :-)

@AparnaKarve
AparnaKarve force-pushed the add_fieldlevelhelp_component branch from a33fc90 to 12fe00e Compare January 24, 2018 19:20
@AparnaKarve

AparnaKarve commented Jan 24, 2018 •

Copy link
Copy Markdown
Contributor Author

@serenamarie125

#1 - can you change the placement of the popover so it "points" at the "I" icon as shown here in the design: http://www.patternfly.org/pattern-library/forms-and-controls/help-on-forms/#design

This is done. Can you please check the storybook again.

#2 - per the design, I think we only support with popover, not tooltip - @jgiardino what do you think? should we remove the tooltip option to be inline with the documentation and ensure consistency?

Let me know what we decide. IMO, tooltips are nice to have.

#3 - this is a nit, but wondering if you could change the example to bring up a new tab when the link in the popover is clicked ? That would be the desired behavior, so if it's easy to change it may be worth it

Addressed the above.

@AparnaKarve

Copy link
Copy Markdown
Contributor Author

@jeff-phillips-18

Adding an action log for the link might be a better choice than adding a tab. Just my $00.02

The link is inside the popover. Not sure how to get the clicking action output in the action log.

@AparnaKarve

AparnaKarve commented Jan 24, 2018 •

Copy link
Copy Markdown
Contributor Author

It will be better if you enable KNOBS panel to change "placement" or "trigger" properties

@dabeng The knobs that are applicable in this case are mode and content and the Field Label itself. I have added those. Can you review the storybook once again?

@AparnaKarve
AparnaKarve force-pushed the add_fieldlevelhelp_component branch from 12fe00e to aeb861d Compare January 24, 2018 19:50
@AparnaKarve

AparnaKarve commented Jan 24, 2018 •

Copy link
Copy Markdown
Contributor Author

@ohadlevy I have added some tests that pass in my environment - but seem to fail on Travis.

Not sure what the below CI error means -

New snapshot was not written. The update flag must be explicitly passed to write a new snapshot.
    
    This is likely because this test is run in a continuous integration (CI) environment in which snapshots are not written by default.

Did I miss something?

@AparnaKarve

Copy link
Copy Markdown
Contributor Author

@priley86 @ohadlevy

Tests in this PR seem to be failing because of the snapshot files.

In the travis configuration, do we need to delete the snapshot files prior to npm run test?

I managed to recreate the CI failure locally, and it looks like running
./node_modules/.bin/jest --updateSnapshot before the tests execute, seems to fix it.

@ohadlevy

Copy link
Copy Markdown
Member

@AparnaKarve you simply need to include the snapshot file too

@AparnaKarve
AparnaKarve force-pushed the add_fieldlevelhelp_component branch from aeb861d to fae5b63 Compare January 24, 2018 20:46
@AparnaKarve

Copy link
Copy Markdown
Contributor Author

Thanks @ohadlevy - that fixed it.

@jeff-phillips-18

Copy link
Copy Markdown
Member

I would agree that this particular component only be onClick per the design at http://www.patternfly.org/pattern-library/forms-and-controls/help-on-forms/#design

Tooltips are useful, but I think we want this component to follow the design to maintain consistency across applications using this.

@ohadlevy ohadlevy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thanks @AparnaKarve I've left a few comments inline


return (
<div>
<label>{children + ' '}</label>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nitpick: please write as:

<label>{`${children} `}</label>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 2dd035d

contentType === 'popover' ? (
<Popover id="{contentType}">{htmlContent}</Popover>
) : (
<Tooltip id="{contentType}">{htmlContent}</Tooltip>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍 to removing tooltip here, its not part of the pf-design.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not removing the tooltip option in this iteration.
Keeping it temporarily for demo purposes, to explain an issue related to Formgroups and Popover below - #179 (comment)

import { defaultTemplate } from '../../../storybook/decorators/storyTemplates';
import { DOCUMENTATION_URL } from '../../../storybook/constants';
import { FieldLevelHelp } from './index';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

maybe we should add it under the forms stories? it makes sense to me to see a complete form with field level help instead of a standalone?

@AparnaKarve AparnaKarve Jan 27, 2018 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In 6c9f1d2, I have added the story under Forms.

It was a good call to add the FieldLevelHelp use case in the Form, since it looks like I may have stumbled upon a bug in the Popover (or OverlayTrigger) component.

When the Popover component is used in conjunction with the FormGroup component, the Formgroup component steals the focus from Popover, causing the popover to close immediately. This happens in a fraction of a second, giving a visual impression that the popover never opened.

Please see a demo of the above issue here -
under the Forms->Horizontal Form->Phone field

For this particular use case, a workaround would be to keep the Popover open - (An option that you requested here - #179 (comment)). That way, we would at least see the popover contents.
The 'Close Popover' knob demonstrates the above (set the value to false)

The other workaround is to use Tooltips - but since we are not considering tooltips for the FieldLevelHelp component, that is probably not an option.
The 'Popover/Tooltip' knob demonstrates the above (set the value to 'tooltip')

<FieldLevelHelp id="fieldlevelname1">Port Number</FieldLevelHelp>
);

let tree = component.toJSON();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I assume you can use const here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 2dd035d

/** Contents displayed with popover or tooltip */
content: PropTypes.string,
/** children nodes */
children: PropTypes.node

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

does it make sense to have a props to force the popover to be open? (instead on just on hover/click)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added a new prop - close, to close/open the popover if the use case needs it.
(if popover is forced to be open, it can be closed after clicking on the 'i' icon)

0db70f4

@jgiardino

Copy link
Copy Markdown
Contributor

Thanks for adding this @AparnaKarve!

I also agree that this should only include the popover, and not the tooltip, to be consistent with the patternfly design documentation.

The only issue I see is with keyboard accessibility. I should be able to use the Tab key to place focus on the element that triggers the popover, and the Enter key to toggle the popover. Currently, the help icon is implemented as a <span> which can't receive keyboard focus. Alternatively, the bootstrap example uses a <button> and the patternfly example uses <a href="#">. (I think the <button> is more appropriate for this case, since we're not navigating anywhere.)

Also, how does this component fit in with the Forms component that currently exists? For example, will I be able to use the Forms component and include this FieldLevelHelp component? Or is additional work needed for either component to support this? And should we include a storybook that shows an example that uses both components? (We can create separate issues to track this work)

@AparnaKarve

AparnaKarve commented Jan 30, 2018 •

Copy link
Copy Markdown
Contributor Author

@jgiardino Thanks for the above feedback.

These are the most recent changes -

  • removed tooltips
  • implemented help icon as a button
    (this seems to have resolved a focus issue that I was seeing earlier, mentioned in Add FieldLevelHelp component #179 (comment), so thanks for the tip)
  • added FieldLevelHelp in the Form stories

Let me know if you find anything else. Thanks.

>
<Button
bsStyle="link"
style={{ textDecoration: 'none', outline: 'none' }}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we remove these styles? Removing the outline results in an accessibility issue, because focus is not obvious to the sighted user who uses a keyboard to navigate.

Also, as a general rule, if styles are ever needed, chances are they should be added to the core patternfly repo so that all JS repos can benefit from them. There are probably rare cases where react has a unique case that exists only in the context of the react repo. In that case we would add .less and .scss files for the component. I just now opened PR #195 to the contributing guide that includes some of these updates, in case you want to review and provide feedback :-)

@jgiardino

Copy link
Copy Markdown
Contributor

Yay, I'm glad using the button solved another issue. That was a happy accident!

I made a comment inline about inline styles. Related to this, I do realize that when the outline is visible, it's right up next to the text which is a little odd. But since there is no html implementation of this pattern in patternfly core that provides an example for us to follow, then I think for now what you have (after you remove the inline styles) is fine. I created an issue in patternfly to capture this: patternfly/patternfly#943

Thank you for updating the Form examples to show the inline help. When I was looking at the html for this example, I noticed some weirdness. The elements div.form-group and input.form-control are both getting attributes content and close:

<div content="Please specify Country code <br> <a target='_blank' href='https://countrycode.org/'>Click here for a list of Country codes</a>" close="true" class="form-group">
  <label for="phone" class="col-sm-3 control-label">
    Phone
    <button type="button" class="btn btn-link" style="text-decoration: none; outline: none;">
      <span aria-hidden="true" class="pficon pficon-info"></span>
    </button>
  </label>
  <div class="col-sm-9">
    <input type="phone" content="Please specify Country code <br> <a target='_blank' href='https://countrycode.org/'>Click here for a list of Country codes</a>" close="true" id="phone" class="form-control">
    <span class="help-block">Enter a valid phone number</span>
  </div>
</div>

@AparnaKarve
AparnaKarve force-pushed the add_fieldlevelhelp_component branch from 580ffd8 to 48995b8 Compare January 31, 2018 00:25
@AparnaKarve

Copy link
Copy Markdown
Contributor Author

@jgiardino I have removed the inline styling and have also addressed the html weirdness from the form stories #179 (comment)
Please take another look. Thanks.

@jeff-phillips-18

Copy link
Copy Markdown
Member

I know it's an issue in lots of places but the focus border on the info tip button encroaches on the label:
image

Can we set less horizontal padding and more horizontal margin to pull in the focus border a bit?

@sharvit

sharvit commented Jan 31, 2018

Copy link
Copy Markdown
Contributor

@jeff-phillips-18, maybe it should just not implemented as a button? I think using a link, or just an icon can solve it without changing the styles (maybe just change the mouse pointer).

@AparnaKarve

Copy link
Copy Markdown
Contributor Author

I think using a link, or just an icon can solve it without changing the styles (maybe just change the mouse pointer).

@sharvit My initial approach to this was just using an icon, but that had it's own set of issues.
One of the major ones being, the one described here - #179 (comment). This focus issue should still be viewable on my github.io fork here -
https://aparnakarve.github.io/patternfly-react
There are some knobs there to keep the popover open, which can be used as a workaround so that the Formgroup input does not steal focus from the open popover.

The other issue with the icon approach is what @jgiardino mentioned above, about keyboard accessibility.

@jgiardino

Copy link
Copy Markdown
Contributor

Using <a> instead of <button> has no effect on the outline issue. Using one of these is necessary due to keyboard accessibility.

Regarding @jeff-phillips-18 suggestion, I'm fine with adding css to the pf-react repo to address the outline issue until pf core has an implementation that we can use. I would suggest something like this:
.field-help-pf: {outline-offset: -6px;}

With the button getting the class: <button class="btn btn-link pf-field-level" ...>

I pinged the css-ers under the patternfly group on slack for feedback about this too, so I may edit this in the near future if I get an alternate suggestion from them.

@priley86

priley86 commented Feb 6, 2018

Copy link
Copy Markdown
Member

one other thing i just now saw... your first commit needs to have commitizen syntax... so something like:

`feat(field-level-help): adds field level help to forms`

@AparnaKarve
AparnaKarve dismissed stale reviews from priley86 and jeff-phillips-18 via f5628db February 6, 2018 20:02
@AparnaKarve
AparnaKarve force-pushed the add_fieldlevelhelp_component branch from 3f1a033 to f5628db Compare February 6, 2018 20:02
@AparnaKarve

Copy link
Copy Markdown
Contributor Author

@priley86 I have reworded the first commit as you have indicated above.

@priley86

priley86 commented Feb 6, 2018

Copy link
Copy Markdown
Member

great job @AparnaKarve ... this looks great to me.

@coveralls

Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 697

  • 7 of 7 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.1%) to 65.245%

Totals Coverage Status
Change from base Build 694: 0.1%
Covered Lines: 901
Relevant Lines: 1223

💛 - Coveralls

1 similar comment
@coveralls

Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 697

  • 7 of 7 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.1%) to 65.245%

Totals Coverage Status
Change from base Build 694: 0.1%
Covered Lines: 901
Relevant Lines: 1223

💛 - Coveralls

@jeff-phillips-18
jeff-phillips-18 merged commit db4e1c1 into patternfly:master Feb 6, 2018
@priley86

priley86 commented Feb 6, 2018

Copy link
Copy Markdown
Member

woohoo 100% @AparnaKarve ! 🎉 🎉 thanks!

@AparnaKarve

Copy link
Copy Markdown
Contributor Author

Thanks everyone for your valuable feedback!

@AparnaKarve
AparnaKarve deleted the add_fieldlevelhelp_component branch February 6, 2018 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants