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
fix(text field): adds missing adapter method notifyIconAction
on Icon
#600
fix(text field): adds missing adapter method notifyIconAction
on Icon
#600
Conversation
Codecov Report
@@ Coverage Diff @@
## rc0.9.0 #600 +/- ##
===========================================
- Coverage 94.45% 94.36% -0.09%
===========================================
Files 61 61
Lines 2561 2575 +14
Branches 372 376 +4
===========================================
+ Hits 2419 2430 +11
- Misses 50 51 +1
- Partials 92 94 +2
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.
Didn't a chance to look at the unit tests but thanks for adding them. I'll look more into them when i get back to a desktop.
packages/text-field/icon/index.tsx
Outdated
@@ -94,15 +108,27 @@ export default class Icon extends React.Component< | |||
removeAttr: (attr: keyof IconState) => ( | |||
this.setState((prevState) => ({...prevState, [attr]: null})) | |||
), | |||
notifyIconAction: () => ( this.props.hasOwnProperty('onSelect') | |||
? this.props.onSelect!() |
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.
First time I'm doing a review on my phone... Do you have a default prop set for onSelect? We can get rid of the hasOwnProperty if you set one to an empty function
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.
I think this might be an appropriate use for hasOwnProperty
. Shortly I will be pushing a change where I eliminate it from the get tabidex().
I consciously chose against the approach of making it a defaultProp. Coincidentally, that is how I first went about it [0]. However, I ran into a problem where onSelect will only fire if tabindex != -1 due to pointer-events being set to none [1]. Since tabindex was not a required property for the passed icon I thought it more straightforward to add it based on if onSelect is present. If its has a default prop it will always be present and tabindex will always be initialized with 0 unless specified. This was the major factor in my decision to drop it as a default property.
I also seem to recall an issue in renderIcon from text-field where It was always passing an onSelect. Alas, I cannot quite recall the issue there and it was never committed. Maybe I was also setting a default prop for onLeadingIconSelect/onTrailingIconSelect?
Take your time on responding. A code review on a phone sounds painful.
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.
That makes sense about the defaultProp...but we don't use hasOwnProperty anywhere else in the library, which makes me suspicious. Either we should be doing that everywhere, or we shouldn't do it here - it just breaks the pattern. If we decide to do it, we should instead open another bug to do it system wide.
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.
I hear you on that mindset....I guess I could do something like the following.
{ notifyIconAction: (() => this.props.onSelect ? this.props.onSelect() : null) }
for some reason I seem to rely heavily on hasOwnProperty() in other projects. Old habits and all... Nevertheless, making this exact change doesn't seem to cause any breaking changes. Will this work for you?
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.
looks good to me!
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.
please see new comments. Once they are fixed I'll review unit tests
@@ -13,7 +13,11 @@ import { | |||
import TestField from './TestTextField'; | |||
|
|||
const textFields = (variantProps: {variant?: string}) => { | |||
return iconsMap.map((icon: {leadingIcon?: React.ReactNode, trailingIcon?: React.ReactNode}) => { | |||
return iconsMap.map((icon: { | |||
leadingIcon?: React.ReactNode, |
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.
something i notice about these tests is that the icon tap target is only 24px x 24px. HIG (human interface guide - I think) says 48x48 is the minimum. I'm not sure what MDC Web does or if this is an issue with MDC Web. I'll follow up with one of our engineers.
@@ -13,7 +13,11 @@ import { | |||
import TestField from './TestTextField'; | |||
|
|||
const textFields = (variantProps: {variant?: string}) => { | |||
return iconsMap.map((icon: {leadingIcon?: React.ReactNode, trailingIcon?: React.ReactNode}) => { | |||
return iconsMap.map((icon: { |
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.
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.
These all have a tabIidex of -1 for me, and thus have no pointer events. Nor should any instance of text-field that has both trailing and leading icons. At least that is how I am reading iconsMaps and TextFieldPermutations. Additionally, at this point get tabindex() in text-field will always set a tabindex. Not allowing it to be undefined.
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.
cool - i think one of your other commits must have fixed it
packages/text-field/icon/README.md
Outdated
@@ -22,6 +22,9 @@ Prop Name | Type | Description | |||
--- | --- | --- | |||
disabled | Boolean | Toggles the disabled state of the icon. | |||
children | Element | Required. Expects a single child icon element. | |||
onSelect | Function() => void | Optional callback for user interaction with icon | |||
> Notes: `onSelect` fired only for clicked event or when keydown event is enter key. |
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.
wording: `fired on click event and "enter key" keydown event.
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.
looks good - minor spelling mistakes.
I will update with screenshot test changes. Please commit once i have them
@mgr34 please update text-field/icon golden.json to |
tests are passing and pr is signed in #600 (comment). Merging! |
Implements missing icon adapter method
notifyIconAction
on<Icon/>
. Accomplished via adding optionalonSelect
to<Icon/>
and correspondingonLeadingIconSelect
andonTrailingIconSelect
on<TextField/>
. Still having trouble with screenshot tests. Should close #585.Note: this is the first I've worked with typescript.
I signed it