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

feat(select): add component #169

Merged
merged 38 commits into from
Aug 3, 2018
Merged

feat(select): add component #169

merged 38 commits into from
Aug 3, 2018

Conversation

moog16
Copy link

@moog16 moog16 commented Jul 23, 2018

fixes #128

@codecov-io
Copy link

codecov-io commented Jul 23, 2018

Codecov Report

Merging #169 into master will decrease coverage by 0.09%.
The diff coverage is 98.07%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
packages/select/index.js 100% <100%> (ø)
packages/select/NativeControl.js 92.3% <92.3%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9dde169...07f647e. Read the comment docs.

@@ -21,6 +21,14 @@ module.exports.bundle = function(testPath, outputPath) {
{
loader: 'css-loader',
},
{
Copy link
Author

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.

@moog16
Copy link
Author

moog16 commented Jul 24, 2018

this might also be an issue: #165

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.


handleFocus = (e) => {
const {foundation, onFocus} = this.props;
foundation.focusHandler_(e);
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 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.

const {foundation, handleValueChange, onChange} = this.props;
const {value} = e.target;

foundation.selectionHandler_(e);
Copy link
Contributor

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

onBlur: PropTypes.func,
onChange: PropTypes.func,
onFocus: PropTypes.func,
setDisabled: PropTypes.func,
Copy link
Contributor

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

Copy link
Author

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.

className: PropTypes.string,
children: PropTypes.node,
disabled: PropTypes.bool,
handleValueChange: PropTypes.func,
Copy link
Contributor

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??

Copy link
Author

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.

children: PropTypes.node,
disabled: PropTypes.bool,
handleValueChange: PropTypes.func,
foundation: PropTypes.shape({
Copy link
Contributor

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?

Copy link
Author

@moog16 moog16 Jul 30, 2018

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.

hasClass: (className) => this.classes.split(' ').includes(className),
isRtl: this.getIsRtl,
getValue: (value) => this.state.value,
// setValue, getSelectedIndex, setSelectedIndex aren't needed
Copy link
Contributor

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.

// and selectedindex themselves
};

const labelAdapter = {
Copy link
Contributor

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}),
Copy link
Contributor

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?

Copy link
Author

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.

);
}

getIsRtl = () => {
Copy link
Contributor

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

Copy link
Author

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?

});
}

renderWithLabel(selectContainer) {
Copy link
Contributor

Choose a reason for hiding this comment

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

just renderLabel

@moog16
Copy link
Author

moog16 commented Aug 1, 2018

TODO: Update main readme table of info

// floating label state
labelIsFloated: false,
labelWidth: 0,
setLineRippleTransformOrigin: (lineRippleCenter) => this.setState({lineRippleCenter}),
Copy link
Contributor

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?

},
hasClass: (className) => this.classes.split(' ').includes(className),
isRtl: () => this.props.isRtl,
getValue: (value) => this.state.value,
Copy link
Contributor

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

});
}

renderLabel(selectContainer) {
Copy link
Contributor

Choose a reason for hiding this comment

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

unused param

export default class Select extends React.Component {

foundation_ = null;
selectContainerElement_ = React.createRef();
Copy link
Contributor

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,
Copy link
Contributor

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?

Copy link
Author

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

Copy link
Contributor

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)

Copy link
Author

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}

@bonniezhou bonniezhou self-assigned this Aug 1, 2018
handleFocus: PropTypes.func,
handleBlur: PropTypes.func,
}),
id: PropTypes.string,
Copy link
Contributor

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)

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.
Copy link
Contributor

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."

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))
Copy link
Contributor

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

}
}
```

Copy link
Contributor

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.

import {shallow} from 'enzyme';
import NativeControl from '../../../packages/select/NativeControl';

suite('Select Native Input');
Copy link
Contributor

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

td.verify(syncSelectValue(value), {times: 1});
});

test('calls props.setDisabled props.disabed', () => {
Copy link
Contributor

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"

children,
foundation,
value,
syncSelectValue,
Copy link
Contributor

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

foundation,
value,
syncSelectValue,
setDisabled,
Copy link
Contributor

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
Copy link
Contributor

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

@@ -5,17 +5,16 @@ import classnames from 'classnames';
export default class NativeControl extends React.Component {

componentDidMount() {
Copy link
Contributor

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

@moog16 moog16 merged commit e619e52 into master Aug 3, 2018
@moog16 moog16 deleted the feat/select branch August 3, 2018 21:07
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.

4 participants