Skip to content
Merged
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ see example
|onValueChange | fire when picker change | Function(value) | |
|children | array of picker items | [{label, value}] |
|pure | whether children is immutable | bool | true
|disabled | whether picker is disabled | bool | false


## Test Case
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rmc-picker",
"version": "3.2.8",
"version": "3.3.0",
"description": "React Mobile Picker Component(web and react-native)",
"keywords": [
"react",
Expand Down Expand Up @@ -46,6 +46,7 @@
},
"dependencies": {
"babel-runtime": "6.x",
"classnames": "~2.2.5",
"object-assign": "4.x",
"rc-dialog": "6.x",
"react-hammerjs": "0.5.x",
Expand Down
28 changes: 20 additions & 8 deletions src/Picker.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {Animate, easeOutCubic, easeInOutCubic} from './Animate.web';
import {PickerProps} from './PickerTypes';
import Hammer from 'react-hammerjs';
import assign from 'object-assign';
import classNames from 'classnames';
import {getComputedStyle } from './utils.web';
import isChildrenEqual from './isChildrenEqual';

Expand Down Expand Up @@ -438,7 +439,7 @@ export default class Picker extends React.Component<PickerProps, PickerState> {
}

render() {
const {children, prefixCls} = this.props;
const {children, prefixCls, className, disabled} = this.props;
const {selectedValue} = this.state;
const itemClassName = `${prefixCls}-item`;
const selectedItemClassName = `${itemClassName} ${prefixCls}-item-selected`;
Expand All @@ -451,6 +452,23 @@ export default class Picker extends React.Component<PickerProps, PickerState> {
{item.label}
</div>);
});
const pickerCls = {
[className]: !!className,
[prefixCls]: true,
[`${prefixCls}-disabled`]: disabled,
};
const child = (
<div className={classNames(pickerCls) } data-role="component" ref="component">
<div className={`${prefixCls}-mask`} data-role="mask"/>
<div className={`${prefixCls}-indicator`} data-role="indicator" ref="indicator"/>
<div className={`${prefixCls}-content`} data-role="content" ref="content">
{items}
</div>
</div>
);
if (disabled) {
Copy link
Member

Choose a reason for hiding this comment

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

不给 hammer 绑定事件就可以了,不要改变层次结构

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

dom 没改变

return child;
}
return (
<Hammer
direction="DIRECTION_ALL"
Expand All @@ -459,13 +477,7 @@ export default class Picker extends React.Component<PickerProps, PickerState> {
onPanEnd={this.onPanEnd}
options={hammerOption}
>
<div className={`${prefixCls}`} data-role="component" ref="component">
<div className={`${prefixCls}-mask`} data-role="mask"/>
<div className={`${prefixCls}-indicator`} data-role="indicator" ref="indicator"/>
<div className={`${prefixCls}-content`} data-role="content" ref="content">
{items}
</div>
</div>
{child}
</Hammer>);
}
}
2 changes: 2 additions & 0 deletions src/PickerTypes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ export interface PickerItem {
export interface PickerProps {
children?:PickerItem[];
pure?:boolean;
disabled?:boolean;
selectedValue?:any;
onValueChange?:(value:any) => void;
/** web only */
prefixCls?:string;
className?:string;
/** web only */
defaultSelectedValue?:any;
}
11 changes: 7 additions & 4 deletions src/PopupMixin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@ export default {
if (!children) {
return this.getModal();
}
const {WrapComponent} = this.props;
const {WrapComponent, disabled} = this.props;
const child = children;
const newChildProps = {
[props.triggerType]: this.onTriggerClick,
};
const newChildProps = {};
if (!!disabled) {
newChildProps['disabled'] = true;
Copy link
Member

Choose a reason for hiding this comment

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

不要传给 child

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

不然 child 怎么知道 disabled 了?不传属性、传个 className 也好

} else {
newChildProps[props.triggerType] = this.onTriggerClick;
}
return <WrapComponent style={props.style}>
{React.cloneElement(child, newChildProps)}
{this.getModal()}
Expand Down
1 change: 1 addition & 0 deletions src/PopupPickerTypes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface PopupPickerProps {
okText?:string;
title?:string;
visible?:boolean;
disabled?:boolean;
onOk?:() => void;
style?:any;
onVisibleChange?:(visible:boolean) => void;
Expand Down