Skip to content

Commit

Permalink
change onSelect API to onAction, resolves #39
Browse files Browse the repository at this point in the history
Affected components:

- Modal
- NavBar
- Slider
- Tabs
- TabBar
  • Loading branch information
minwe committed Apr 25, 2016
1 parent 89bc1ff commit 93fac1f
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 35 deletions.
2 changes: 1 addition & 1 deletion docs/modal/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Modal 标题。
点击遮罩层是否关闭 Modal。

##### `onSelect`
##### `onAction`

> PropType: `func`
Expand Down
2 changes: 1 addition & 1 deletion docs/navbar/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const leftNav = [
主标题是否居左,默认居中。

##### `onSelect`
##### `onAction`

> PropType: `func`
Expand Down
2 changes: 1 addition & 1 deletion docs/slider/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
默认激活的幻灯片编号。

##### `onSelect`
##### `onAction`

> PropType: `func`
Expand Down
2 changes: 1 addition & 1 deletion docs/tabbar/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
- `'alert'`
- `'dark'`

##### `onSelect`
##### `onAction`

> PropType: `func`
Expand Down
2 changes: 1 addition & 1 deletion docs/tabs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
激活选项卡的 `eventKey`

##### `onSelect`
##### `onAction`

> PropType: `func`
Expand Down
4 changes: 2 additions & 2 deletions kitchen-sink/pages/ModalExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const ModalExample = React.createClass({
this.refs.modal.close();
},

handleSelect(data) {
handleAction(data) {
let role = this.refs.modal.props.role;

// 确定和取消放在一起处理
Expand All @@ -41,7 +41,7 @@ const ModalExample = React.createClass({

{React.cloneElement(React.Children.only(this.props.children), {
ref: 'modal',
onSelect: this.handleSelect
onAction: this.handleAction
})}
</div>
);
Expand Down
6 changes: 3 additions & 3 deletions kitchen-sink/pages/NavBarExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ const dataAll = {
title: 'Navbar',
leftNav: [{...itemLeft, icon: 'left-nav'}],
rightNav: [{...itemRight, icon: 'right-nav'}],
onSelect: clickHandler,
onAction: clickHandler,
};

const dataLeft = {
title: 'Navbar',
leftNav: [{...itemLeft, icon: 'left-nav'}],
onSelect: clickHandler,
onAction: clickHandler,
};

const dataRight = {
title: 'Navbar',
rightNav: [itemRight, itemRight],
onSelect: clickHandler,
onAction: clickHandler,
};

const NavBarExample = React.createClass({
Expand Down
2 changes: 1 addition & 1 deletion kitchen-sink/pages/TabBarExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const TabBarDemo = React.createClass({
return (
<TabBar
amStyle="primary"
onSelect={this.handleClick}
onAction={this.handleClick}
>
<TabBar.Item
eventKey="home"
Expand Down
16 changes: 9 additions & 7 deletions src/js/Accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const Accordion = React.createClass({
activeKey: React.PropTypes.any,
defaultActiveKey: React.PropTypes.any,
inset: React.PropTypes.bool,
onSelect: React.PropTypes.func,
onAction: React.PropTypes.func,
},

getDefaultProps() {
Expand All @@ -28,16 +28,16 @@ const Accordion = React.createClass({
},

shouldComponentUpdate: function() {
// Defer any updates to this component during the `onSelect` handler.
// Defer any updates to this component during the `onAction` handler.
return !this._isChanging;
},

handleSelect(e, key) {
e.preventDefault();

if (this.props.onSelect) {
if (this.props.onAction) {
this._isChanging = true;
this.props.onSelect(key);
this.props.onAction(key);
this._isChanging = false;
}

Expand All @@ -60,7 +60,7 @@ const Accordion = React.createClass({
} = child.props;
let props = {
key: index,
onSelect: this.handleSelect,
onAction: this.handleSelect,
};

if (eventKey === undefined) {
Expand Down Expand Up @@ -98,10 +98,12 @@ Accordion.Item = React.createClass({
},

handleClick: function(e) {
// @see https://facebook.github.io/react/docs/events.html#event-pooling
e.persist();
e.selected = true;

if (this.props.onSelect) {
this.props.onSelect(e, this.props.eventKey);
if (this.props.onAction) {
this.props.onAction(e, this.props.eventKey);
} else {
e.preventDefault();
}
Expand Down
6 changes: 3 additions & 3 deletions src/js/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const Modal = React.createClass({
cancelText: React.PropTypes.string,
closeBtn: React.PropTypes.bool,
closeViaBackdrop: React.PropTypes.bool,
onSelect: React.PropTypes.func,
onAction: React.PropTypes.func,
onOpen: React.PropTypes.func,
onClosed: React.PropTypes.func,
},
Expand All @@ -40,7 +40,7 @@ const Modal = React.createClass({
confirmText: '确定',
cancelText: '取消',
closeBtn: true,
onSelect: () => {
onAction: () => {
},
onOpen: () => {
},
Expand Down Expand Up @@ -97,7 +97,7 @@ const Modal = React.createClass({
}

this.close();
this.props.onSelect.call(this, data, e);
this.props.onAction.call(this, data, e);
},

open() {
Expand Down
6 changes: 3 additions & 3 deletions src/js/NavBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ const NavBar = React.createClass({
leftNav: React.PropTypes.array,
rightNav: React.PropTypes.array,
titleOnLeft: React.PropTypes.bool,
onSelect: React.PropTypes.func,
onAction: React.PropTypes.func,
},

getDefaultProps() {
return {
classPrefix: 'navbar',
onSelect: () => {
onAction: () => {
},
};
},
Expand Down Expand Up @@ -83,7 +83,7 @@ const NavBar = React.createClass({
<Component
href={item.href}
key={'navbarNavItem' + index}
onClick={this.props.onSelect.bind(this, item)}
onClick={this.props.onAction.bind(this, item)}
{...itemProps}
className={classNames(this.prefixClass('nav-item'), itemProps.className)}
>
Expand Down
6 changes: 3 additions & 3 deletions src/js/Slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const Slider = React.createClass({
pauseOnHover: React.PropTypes.bool,
// touch: React.PropTypes.bool,

onSelect: React.PropTypes.func,
onAction: React.PropTypes.func,
onSlideEnd: React.PropTypes.func,
activeIndex: React.PropTypes.number,
defaultActiveIndex: React.PropTypes.number,
Expand Down Expand Up @@ -186,8 +186,8 @@ const Slider = React.createClass({

direction = direction || this.getDirection(previousActiveIndex, index);

if (this.props.onSelect) {
this.props.onSelect(index, direction);
if (this.props.onAction) {
this.props.onAction(index, direction);
}

if (this.props.activeIndex == null && index !== previousActiveIndex) {
Expand Down
10 changes: 5 additions & 5 deletions src/js/TabBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ let TabBar = React.createClass({
classPrefix: React.PropTypes.string,
component: React.PropTypes.node,
amStyle: React.PropTypes.string,
onSelect: React.PropTypes.func,
onAction: React.PropTypes.func,
},

getDefaultProps() {
return {
classPrefix: 'tabbar',
component: 'nav',
onSelect: function() {}
onAction: function() {}
};
},

Expand All @@ -29,7 +29,7 @@ let TabBar = React.createClass({
component: Component,
className,
children,
onSelect,
onAction,
...props
} = this.props;

Expand All @@ -44,7 +44,7 @@ let TabBar = React.createClass({
onClick,
...props
} = child.props;
let clickHandler = onClick || onSelect;
let clickHandler = onClick || onAction;
let key = eventKey || index;
eventKey = eventKey || key;

Expand Down Expand Up @@ -89,7 +89,7 @@ TabBar.Item = React.createClass({
return {
classPrefix: 'tabbar',
component: 'span',
onSelect: function() {
onAction: function() {
}
};
},
Expand Down
6 changes: 3 additions & 3 deletions src/js/Tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const Tabs = React.createClass({
propTypes: {
classPrefix: React.PropTypes.string,
defaultActiveKey: React.PropTypes.any,
onSelect: React.PropTypes.func,
onAction: React.PropTypes.func,
},

getDefaultProps() {
Expand Down Expand Up @@ -59,8 +59,8 @@ const Tabs = React.createClass({
return null;
}

if (this.props.onSelect) {
this.props.onSelect(key);
if (this.props.onAction) {
this.props.onAction(key);
}

if (activeKey !== key) {
Expand Down

0 comments on commit 93fac1f

Please sign in to comment.