Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions assets/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,13 @@
&-disabled {
color: #ccc;
cursor: not-allowed;
pointer-events: none;
}

&-disabled &-selection {
cursor: not-allowed;
&:hover, &:active {
border-color: #d9d9d9;
box-shadow: none;
}
}

Expand Down Expand Up @@ -460,4 +461,4 @@
border-width: 0 4px 5px 4px;
}
}
}
}
Empty file added examples/common/disabled.js
Empty file.
1 change: 1 addition & 0 deletions examples/disabled.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
placeholder
86 changes: 86 additions & 0 deletions examples/disabled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import React from 'react';
import Select, {Option} from 'rc-select';
import 'rc-select/assets/index.less';
import ReactDOM from 'react-dom';

const children = [];
for (let i = 10; i < 36; i++) {
children.push(<Option key={i.toString(36) + i}>{i.toString(36) + i}</Option>);
}

const Test = React.createClass({
getInitialState() {
return {
destroy: false,
value: '1',
};
},

onChange(e) {
let value;
if (e.target) {
value = e.target.value;
} else {
value = e;
}
this.setState({value});
},

handleDestroy() {
this.setState({
destroy: 1,
});
},

render() {
if (this.state.destroy) {
return null;
}
const dropdownMenuStyle = {
maxHeight: 200,
overflow: 'auto',
};
return (
<div style={{margin: 20}}>
<div style={{height: 150}}/>

<h2>Single Disabled Select</h2>

<div style={{width: 300}}>
<Select disabled
value={this.state.value}
dropdownMenuStyle={{maxHeight: 200, overflow: 'auto'}}
style={{width: 500}}
onChange={this.onChange}>
<Option value="jack">
<b style={{
color: 'red',
}}>jack</b>
</Option>
<Option value="lucy">lucy</Option>
<Option value="disabled" disabled>disabled</Option>
<Option value="yiminghe">yiminghe</Option>
{[1, 2, 3, 4, 5, 6, 7, 8, 9].map((i) => {
return <Option key={i + ''}>{i + ''}</Option>;
})}
</Select>
</div>

<h2>Multiple Disabled Select</h2>

<div style={{width: 300}}>
<Select disabled
animation={this.state.useAnim ? 'slide-up' : null}
dropdownMenuStyle={dropdownMenuStyle}
style={{width: 500}}
multiple
defaultValue={['name2', 'name3']}>
{children}
</Select>
</div>
</div>
);
},
});

ReactDOM.render(<Test />, document.getElementById('__react-content'));
4 changes: 4 additions & 0 deletions src/Select.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ const Select = React.createClass({
},

onDropdownVisibleChange(open) {
const props = this.props;
if (props.disabled) {
return;
}
this.setOpenState(open);
},

Expand Down
12 changes: 12 additions & 0 deletions tests/Select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ describe('Select', () => {
expect(TestUtils.scryRenderedDOMComponentsWithClass(instance, 'rc-select-selection__clear').length).to.be(1);
});

it.only('should not response click event when select is disabled', (done) => {
instance = ReactDOM.render(
<Select disabled defaultValue="2">
<Option value="1">1</Option>
<Option value="2">2</Option>
</Select>, div);
Simulate.click(ReactDOM.findDOMNode(instance.refs.selection));
console.log(instance.state);
expect(instance.state.open).to.be(undefined);
done();
});

describe('when open', function test() {
this.timeout(400000);

Expand Down