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

[Form controls] Added alert icon indicators for invalid state #5738

Merged
merged 24 commits into from
Mar 30, 2022

Conversation

cchaos
Copy link
Contributor

@cchaos cchaos commented Mar 21, 2022

Partially tackles #2017

[EuiFormControlLayout]

  • Added isInvalid prop which is passed through to EuiFormControlLayoutIcon which renders the alert icon in red (danger)
  • Added isDropdown to create and control the arrowDown icon (better for quickly creating this internally and handles visibility based on readOnly and disabled states
  • Added color as a possible option for the IconObject (more configuration options that I needed for color picker)

Passed the isInvalid through for only the following form controls

  • EuiFieldNumber, EuiFieldPassword, EuiFieldText, EuiSelect, EuiSuperSelect, EuiFieldSearch
  • The rest to be done in a follow up PR, these were just the easy ones

Screen Shot 2022-03-22 at 22 51 05 PM

To test, I've set all the Display Toggles to be on by default (I'll revert this before merging).

New Sass method of applying left/right padding based on number of icons

  • Added a getFormControlClassNameForIconCount localized service for counting icons based on boolean state variables
  • Changed className output from rendering component-specific to generic to reduce output styles. So instead of .euiFieldText--isInvalid.euiFieldText--hasIcon and all those combinations of state-produced classes, the above service passes back euiFormControlLayout--2icons that's applied to the form control. So we only have 5 (1-5 number of icons possible) classes total for handling padding vs how every many permutations per control.

[EuiColorPicker] Fixed usage of EuiFormControlLayout to not double

In order for the EuiColorPicker to have an icon on the left (color swatch) and the dropdown arrow on the right, it had to create a second EuiFormControlWrapper to add it. Now with the ability to just say isDropdown to add the arrow icon, we no longer need the second wrapper. But instead of being able to just remove the manual wrapper I had to set controlOnly on the EuiFieldText component because we needed to support the clear prop.

Screen Shot 2022-03-22 at 22 52 29 PM

[EuiSelect] & [EuiSuperSelect] Updated to new props of EuIFormControlLayout

These components now use the isDropdown prop instead of a custom icon. I was also able to fix a couple other quick issues:

Screen Shot 2022-03-21 at 23 11 10 PM

Checklist

  • Checked in both light and dark modes
  • Checked in mobile
  • Checked in Chrome, Safari, Edge, and Firefox
  • Props have proper autodocs and playground toggles
  • Added documentation
  • Checked Code Sandbox works for any docs examples
  • Added or updated jest and cypress tests
  • [ ] Checked for breaking changes and labeled appropriately
  • Checked for accessibility including keyboard-only and screenreader modes
  • Updated the Figma library counterpart
  • A changelog entry exists and is marked appropriately

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5738/

cchaos added 3 commits March 21, 2022 22:41
- Fixed EuiSuperSelect border radius with append/prepend elastic#5442
- Fixed EuiSuperSelect not respecting `readOnly` elastic#3510
@cchaos cchaos marked this pull request as ready for review March 22, 2022 03:12
@cchaos
Copy link
Contributor Author

cchaos commented Mar 22, 2022

Ok, this PR is ready for review as I go through the final checklist. Please be sure to read through the PR summary as this PR only tackles some of the form controls.

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5738/

Comment on lines 59 to 65
<eui-validatable-control
isinvalid="true"
>
<input
class="euiFieldNumber"
class="euiFieldNumber euiFormControlLayout--1icons"
type="number"
/>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know why in the snapshots it's not adding that aria-invalid to the <input>. The one place I did see it get added was in the EuiSuggest snapshot https://github.com/elastic/eui/pull/5738/files#diff-4cd42a1237d4c776e9fd1140e106d4ba0d063ec3a7010a7646ca74236b040f8a

Copy link
Contributor

Choose a reason for hiding this comment

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

I think because EuiValidatableControl is getting mocked in the test file:

jest.mock('../validatable_control', () => ({
EuiValidatableControl: 'eui-validatable-control',
}));

So the cloneElement additions don't happen. Not sure if that mock is still necessary.

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5738/

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5738/

Copy link
Contributor

@elizabetdev elizabetdev left a comment

Choose a reason for hiding this comment

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

LGTM! 🎉

I looked at the code and tested it in Firefox, Safari, Chrome, and Edge.

I also found two minor issues.

  1. The EuiColorPalettePicker needs to handle better the spacing when is compresseed:

Screenshot 2022-03-23 at 17 56 11

  1. I think the CodeSandbox demos need to have the @emotion/react imported in the demo.tsx file.

@cchaos
Copy link
Contributor Author

cchaos commented Mar 23, 2022

No. 1 should be fixed, I was re-calculating the spacing between icons to be smaller in compressed but in fact it never was changing.

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5738/

Copy link
Contributor

@1Copenut 1Copenut left a comment

Choose a reason for hiding this comment

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

LGTM! The Color Palette Picker is receiving the isInvalid prop correctly, but isn't announcing itself as an invalid text field b/c of the button + listbox structure. Not a problem, just an item we should review and strategize ways to announce as invalid in another issue.

Copy link
Contributor

@thompsongl thompsongl left a comment

Choose a reason for hiding this comment

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

Just the one question. Everything is looking good!

Co-authored-by: Greg Thompson <thompson.glowe@gmail.com>
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5738/

cchaos and others added 2 commits March 30, 2022 16:00
This reverts commit fce7b90.

# Conflicts:
#	src-docs/src/views/form_controls/display_toggles.js
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5738/

@cchaos cchaos enabled auto-merge (squash) March 30, 2022 20:37
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5738/

@cchaos cchaos merged commit d31f753 into elastic:main Mar 30, 2022
@cchaos cchaos deleted the form_controls/invalid_icon branch April 1, 2022 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants