-
Notifications
You must be signed in to change notification settings - Fork 227
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(select): add component #169
Conversation
Codecov Report
@@ Coverage Diff @@
## master #169 +/- ##
=========================================
- Coverage 98.79% 98.69% -0.1%
=========================================
Files 18 20 +2
Lines 664 768 +104
Branches 62 69 +7
=========================================
+ Hits 656 758 +102
- Misses 8 10 +2
Continue to review full report at Codecov.
|
@@ -21,6 +21,14 @@ module.exports.bundle = function(testPath, outputPath) { | |||
{ | |||
loader: 'css-loader', | |||
}, | |||
{ |
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.
screenshot tests looked strange without this...I noticed that the appearance: none
rule was not being applied. Chrome needs the -webkit-appearance: none
rule to apply.
EDIT: I don't think this is an issue, since select only has a set amount of values it can be. The way in which the value is managed is slightly different than text-field, which avoids the issue. |
packages/select/NativeControl.js
Outdated
|
||
handleFocus = (e) => { | ||
const {foundation, onFocus} = this.props; | ||
foundation.focusHandler_(e); |
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 you need to open a PR in MDCW to change the MDCSelectFoundation to have handleFocus and handleBlur methods.
This "private" method focusHandler_
is not something we can depend on, because it is not documented in the MDCW documentation.
packages/select/NativeControl.js
Outdated
const {foundation, handleValueChange, onChange} = this.props; | ||
const {value} = e.target; | ||
|
||
foundation.selectionHandler_(e); |
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.
The MDCW PR should also change selectionHandler_ to handleChange
packages/select/NativeControl.js
Outdated
onBlur: PropTypes.func, | ||
onChange: PropTypes.func, | ||
onFocus: PropTypes.func, | ||
setDisabled: PropTypes.func, |
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.
should this be onDisabled
? instead of setDisabled
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.
The convention is that on
indicates an event. Disabled is just a state or attribute, so it seems more appropriate to call it setDisabled.
packages/select/NativeControl.js
Outdated
className: PropTypes.string, | ||
children: PropTypes.node, | ||
disabled: PropTypes.bool, | ||
handleValueChange: PropTypes.func, |
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.
Whats the difference between handleValueChange
and onChange
??
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.
onChange is the event handler - its a React term so we shouldn't change that one. handleValueChange
could be renamed. Does renaming to syncSelectValue
make more sense? It's to update the parent's value.
packages/select/NativeControl.js
Outdated
children: PropTypes.node, | ||
disabled: PropTypes.bool, | ||
handleValueChange: PropTypes.func, | ||
foundation: PropTypes.shape({ |
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 assume the foundation is a prop because you need the parent component to pass the foundation to this NativeControl?
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.
Yes, we call 2 functions from the foundation.
packages/select/index.js
Outdated
hasClass: (className) => this.classes.split(' ').includes(className), | ||
isRtl: this.getIsRtl, | ||
getValue: (value) => this.state.value, | ||
// setValue, getSelectedIndex, setSelectedIndex aren't needed |
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.
should we file an issue on MDCW to remove getSelectedIndex and setSelectedIndex from the adapter? Maybe they should only be in the Vanilla component.
packages/select/index.js
Outdated
// and selectedindex themselves | ||
}; | ||
|
||
const labelAdapter = { |
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.
you didn't implement shakeLabel...is that on purpose?
|
||
const lineRippleAdapter = { | ||
activateBottomLine: () => this.setState({activeLineRipple: true}), | ||
deactivateBottomLine: () => this.setState({activeLineRipple: false}), |
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 implement setLineRippleTransformOrigin... is that on purpose?
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.
MDC Select doesn't call that specific line ripple adapter method. It was filed as a bug a week-ish ago.
packages/select/index.js
Outdated
); | ||
} | ||
|
||
getIsRtl = () => { |
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.
this is copy/pasted from text field. You should move this to a RTL package, and then reference it from both text field and select
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.
You mean create a component and wrap text-field and select? The only thing in that component would be this isRtl method. Is that what you are thinking?
packages/select/index.js
Outdated
}); | ||
} | ||
|
||
renderWithLabel(selectContainer) { |
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.
just renderLabel
TODO: Update main readme table of info |
packages/select/index.js
Outdated
// floating label state | ||
labelIsFloated: false, | ||
labelWidth: 0, | ||
setLineRippleTransformOrigin: (lineRippleCenter) => this.setState({lineRippleCenter}), |
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.
Why is this in state?
packages/select/index.js
Outdated
}, | ||
hasClass: (className) => this.classes.split(' ').includes(className), | ||
isRtl: () => this.props.isRtl, | ||
getValue: (value) => this.state.value, |
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.
getValue
should take no params
packages/select/index.js
Outdated
}); | ||
} | ||
|
||
renderLabel(selectContainer) { |
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.
unused param
packages/select/index.js
Outdated
export default class Select extends React.Component { | ||
|
||
foundation_ = null; | ||
selectContainerElement_ = React.createRef(); |
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.
Can we remove this ref? It doesn't look like it's being used
handleFocus: PropTypes.func, | ||
handleBlur: PropTypes.func, | ||
}), | ||
id: PropTypes.string, |
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.
When is id
being used?
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.
Its used for floatingLabel and associating it for screenreaders
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.
The id should also be passed to the NativeControl from Select then (right now it's only passed to FloatingLabel)
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.
It is being passed to the id through {...otherProps}
handleFocus: PropTypes.func, | ||
handleBlur: PropTypes.func, | ||
}), | ||
id: PropTypes.string, |
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.
The id should also be passed to the NativeControl from Select then (right now it's only passed to FloatingLabel)
packages/select/README.md
Outdated
floatingLabelClassName | String | An optional class added to the floating label element. | ||
id | String | Id of the `<select>` element. | ||
label | String | Mandatory. Label text that appears as the floating label. | ||
isRtl | Boolean | If toggle from false to true or vice-versa, it will recalculate the notched outline element to the appropriate width and positioning. |
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.
Description should be "Whether the direction of the select is set to RTL."
packages/select/README.md
Outdated
Sass mixins may be available to customize various aspects of the Components. Please refer to the | ||
MDC Web repository for more information on what mixins are available, and how to use them. | ||
|
||
[Advanced Sass Mixins]([Advanced Sass Mixins](https://github.com/material-components/material-components-web/blob/master/packages/mdc-select/README.md#sass-mixins)) |
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's an extra [Advanced Sass Mixins]
here
} | ||
} | ||
``` | ||
|
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.
We should add a note somewhere about the first option being a placeholder like here in MDC Web.
test/unit/select/NativeInput.test.js
Outdated
import {shallow} from 'enzyme'; | ||
import NativeControl from '../../../packages/select/NativeControl'; | ||
|
||
suite('Select Native Input'); |
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.
rename this test suite and file to be NativeControl.test.js
test/unit/select/NativeInput.test.js
Outdated
td.verify(syncSelectValue(value), {times: 1}); | ||
}); | ||
|
||
test('calls props.setDisabled props.disabed', () => { |
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.
"calls props.setDisabled if props.disabled is true"
packages/select/NativeControl.js
Outdated
children, | ||
foundation, | ||
value, | ||
syncSelectValue, |
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.
remove syncSelectedValue....the parent component should use the onChange prop callback for this
packages/select/NativeControl.js
Outdated
foundation, | ||
value, | ||
syncSelectValue, | ||
setDisabled, |
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.
change this to handleDisabled, its a callback to an event essentially
|
||
> NOTE: In order to get access to the value, you must add an `onChange` handler, which accepts an event and updates the value of the select as shown above. | ||
|
||
#### Shorthand options |
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.
Can you add some more information in the README about the use case where JSON comes from the API
packages/select/NativeControl.js
Outdated
@@ -5,17 +5,16 @@ import classnames from 'classnames'; | |||
export default class NativeControl extends React.Component { | |||
|
|||
componentDidMount() { |
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.
try removing this, i dont think we need it
fixes #128