Skip to content

Commit

Permalink
add types and Fixes ant-design/ant-design#2273
Browse files Browse the repository at this point in the history
  • Loading branch information
yiminghe committed Aug 12, 2016
1 parent 59d1c8c commit 3c7f459
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 30 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rc-select",
"version": "6.4.7",
"version": "6.4.8",
"description": "React Select",
"keywords": [
"react",
Expand Down Expand Up @@ -29,7 +29,7 @@
"build": "rc-tools run build",
"gh-pages": "rc-tools run gh-pages",
"start": "rc-tools run server",
"pub": "rc-tools run pub",
"pub": "rc-tools run pub --babel-runtime",
"lint": "rc-tools run lint",
"karma": "rc-tools run karma",
"saucelabs": "rc-tools run saucelabs",
Expand All @@ -44,13 +44,14 @@
"jsonp": "^0.2.0",
"pre-commit": "1.x",
"querystring": "^0.2.0",
"rc-dialog": "^5.3.1",
"rc-dialog": "6.x",
"rc-tools": "5.x",
"react": "15.x",
"react-addons-test-utils": "15.x",
"react-dom": "15.x"
},
"dependencies": {
"babel-runtime": "6.x",
"classnames": "2.x",
"component-classes": "1.x",
"dom-scroll-into-view": "1.x",
Expand Down
4 changes: 3 additions & 1 deletion src/Option.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React from 'react';

export default class Option extends React.Component {

static propTypes = {
value: React.PropTypes.string,
};
}
27 changes: 24 additions & 3 deletions src/Select.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ function saveRef(name, component) {
this[name] = component;
}

let valueObjectShape;

if (PropTypes) {
valueObjectShape = PropTypes.oneOfType([
PropTypes.string,
PropTypes.shape({
key: PropTypes.string,
label: PropTypes.node,
}),
]);
}

const Select = React.createClass({
propTypes: {
defaultActiveFirstOption: PropTypes.bool,
Expand All @@ -50,8 +62,14 @@ const Select = React.createClass({
placeholder: PropTypes.any,
onDeselect: PropTypes.func,
labelInValue: PropTypes.bool,
value: PropTypes.any,
defaultValue: PropTypes.any,
value: PropTypes.oneOfType([
valueObjectShape,
PropTypes.arrayOf(valueObjectShape),
]),
defaultValue: PropTypes.oneOfType([
valueObjectShape,
PropTypes.arrayOf(valueObjectShape),
]),
dropdownStyle: PropTypes.object,
maxTagTextLength: PropTypes.number,
},
Expand Down Expand Up @@ -302,8 +320,9 @@ const Select = React.createClass({
this.updateFocusClassName();
const props = this.props;
let { value } = this.state;
const { inputValue } = this.state;
if (isSingleMode(props) && props.showSearch &&
this.state.inputValue && props.defaultActiveFirstOption) {
inputValue && props.defaultActiveFirstOption) {
const options = this._options || [];
if (options.length) {
const firstOption = findFirstMenuItem(options);
Expand All @@ -315,6 +334,8 @@ const Select = React.createClass({
this.fireChange(value);
}
}
} else if (isMultipleOrTags(props) && inputValue) {
this.state.inputValue = this.getInputDOMNode().value = '';
}
props.onBlur(this.getVLForOnChange(value));
}, 10);
Expand Down
23 changes: 0 additions & 23 deletions tests/Select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,6 @@ describe('Select', () => {
});
});

it('allow number value', (done) => {
function onChange(v) {
expect(v).to.be(1);
done();
}
instance = ReactDOM.render(
<Select
onChange={onChange}
value={2}
>
<Option value={1}>1</Option>
<Option value={2}>2</Option>
</Select>,
div);
instance.setState({
open: true,
});
let activeItem = $(instance.getPopupDOMNode()).find('.rc-select-dropdown-menu-item-active')[0];
expect(activeItem.innerHTML).to.be('2');
activeItem = $(instance.getPopupDOMNode()).find('.rc-select-dropdown-menu-item')[0];
Simulate.click(activeItem);
});

it('should add css class of root dom node', () => {
instance = ReactDOM.render(
<Select className="forTest" openClassName="my-open" value="2">
Expand Down

0 comments on commit 3c7f459

Please sign in to comment.