diff --git a/src/components/tabmenu/TabMenu.css b/src/components/tabmenu/TabMenu.css index 5a2c2b4587..99dfd57403 100644 --- a/src/components/tabmenu/TabMenu.css +++ b/src/components/tabmenu/TabMenu.css @@ -1,39 +1,35 @@ /** TabMenu **/ -.ui-tabmenu { - -} - -.ui-tabmenu .ui-tabmenu-nav { +.ui-tabmenu .ui-tabmenu-nav { margin: 0; - padding: .25em .5em 0 .25em; + padding: .25em .5em 0 .25em; } -.ui-tabmenu .ui-tabmenu-nav .ui-tabmenuitem { - list-style: none; - float: left; - position: relative; - margin: 0 .2em 1px 0; - padding: 0; +.ui-tabmenu .ui-tabmenu-nav .ui-tabmenuitem { + list-style: none; + float: left; + position: relative; + margin: 0 .2em 1px 0; + padding: 0; white-space: nowrap; display: block; border-bottom: 0; - top: 1px; + top: 1px; } -.ui-tabmenu .ui-tabmenu-nav .ui-tabmenuitem a { - float: left; +.ui-tabmenu .ui-tabmenu-nav .ui-tabmenuitem a { + float: left; padding: 0.5em 1em; - text-decoration: none; + text-decoration: none; } -.ui-tabmenu .ui-tabmenu-nav a { +.ui-tabmenu .ui-tabmenu-nav a { padding: 0.5em 1em; } -.ui-tabmenu .ui-tabmenu-nav .ui-tabmenuitem .ui-icon { - float: left; +.ui-tabmenu .ui-menuitem-icon { + margin-right: .25em; } .ui-tabmenu .ui-tabmenu-nav .ui-tabmenuitem.ui-state-disabled a { - cursor: default; + cursor: default; } \ No newline at end of file diff --git a/src/components/tabmenu/TabMenu.js b/src/components/tabmenu/TabMenu.js index c01cd64727..62d2208e6f 100644 --- a/src/components/tabmenu/TabMenu.js +++ b/src/components/tabmenu/TabMenu.js @@ -1,70 +1,107 @@ import React, {Component} from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; -import {MenuItem} from '../menu/MenuItem' export class TabMenu extends Component { static defaultProps = { id: null, - model:null, - activeItem:null, - style:null, - className:null, + model: null, + activeItem: null, + style: null, + className: null }; static propTypes = { id: PropTypes.string, - model:PropTypes.array, - activeItem:PropTypes.any, - style:PropTypes.any, - className:PropTypes.string, + model: PropTypes.array, + activeItem: PropTypes.any, + style: PropTypes.any, + className: PropTypes.string }; - constructor(props) { super(props); - this.state ={activeItem:this.props.activeItem || this.props.model[0]}; + this.state = { + activeItem: props.activeItem || props.model ? props.model[0] : null + }; + } + + static getDerivedStateFromProps(nextProps, prevState) { + if(nextProps.activeItem && nextProps.activeItem !== prevState.activeItem) { + return { + activeItem: nextProps.activeItem + }; + } + + return null; } itemClick(event, item) { - if(item.disabled) { + if (item.disabled) { event.preventDefault(); return; } - if(!item.url) { + if (!item.url) { event.preventDefault(); } - if(item.command) { + if (item.command) { item.command({ originalEvent: event, item: item }); } - this.setState({activeItem:item}); + if(this.props.onChange) { + this.props.onChange({ + originalEvent: event, + value: item + }); + } + + this.setState({activeItem: item}); } - render() { - var tabMenuClass=classNames('ui-tabmenu ui-widget ui-widget-content ui-corner-all',this.props.className); + renderMenuItem(item, index) { + const className = classNames('ui-tabmenuitem ui-state-default ui-corner-top', {'ui-state-active': this.state.activeItem === item}); + const iconClassName = classNames(item.icon, 'ui-menuitem-icon'); + const icon = item.icon ? : null; - var item=this.props.model && this.props.model.map((item,index)=>{ - var listClass=classNames('ui-tabmenuitem ui-state-default ui-corner-top',{'ui-state-disabled':item.disabled}, - {'ui-tabmenuitem-hasicon':item.icon},{'ui-state-active':this.state.activeItem===item}) - var list=