Skip to content

Commit

Permalink
Merge pull request alibaba-fusion#1445 from youluna/fix-design-pro
Browse files Browse the repository at this point in the history
Fix bugs for design pro
  • Loading branch information
myronliu347 authored Dec 12, 2019
2 parents e0fea35 + 83db668 commit 29b0d63
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/form/style.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import '../grid/style.js';
import '../responsive-grid/style.js';
import '../button/style.js';
import './main.scss';
47 changes: 39 additions & 8 deletions src/menu/view/menu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -306,23 +306,33 @@ export default class Menu extends Component {
}

adjustChildrenWidth() {
const { direction, prefix, hozInLine } = this.props;
const { direction, prefix, header, footer, hozInLine } = this.props;
if (direction !== 'hoz' || !hozInLine) {
return;
}

if (!this.menuNode) {
if (!this.menuNode && !this.menuContent) {
return;
}

const children = this.menuNode.children;
let children = [],
spaceWidth;

if (header || footer) {
children = this.menuContent.children;
spaceWidth =
getWidth(this.menuNode) -
getWidth(this.menuHeader) -
getWidth(this.menuFooter);
} else {
children = this.menuNode.children;
spaceWidth = getWidth(this.menuNode);
}

if (children.length < 2) {
return;
}

const spaceWidth = getWidth(this.menuNode);

let currentSumWidth = 0,
lastVisibleIndex = -1;

Expand Down Expand Up @@ -920,6 +930,18 @@ export default class Menu extends Component {
}
}

menuContentRef = ref => {
this.menuContent = ref;
};

menuHeaderRef = ref => {
this.menuHeader = ref;
};

menuFooterRef = ref => {
this.menuFooter = ref;
};

render() {
const {
prefix,
Expand Down Expand Up @@ -952,16 +974,25 @@ export default class Menu extends Component {
}

const headerElement = header ? (
<li className={`${prefix}menu-header`}>{header}</li>
<li className={`${prefix}menu-header`} ref={this.menuHeaderRef}>
{header}
</li>
) : null;
const itemsElement =
header || footer ? (
<ul className={`${prefix}menu-content`}>{this.newChildren}</ul>
<ul
className={`${prefix}menu-content`}
ref={this.menuContentRef}
>
{this.newChildren}
</ul>
) : (
this.newChildren
);
const footerElement = footer ? (
<li className={`${prefix}menu-footer`}>{footer}</li>
<li className={`${prefix}menu-footer`} ref={this.menuFooterRef}>
{footer}
</li>
) : null;
const shouldWrapItemsAndFooter = hozAlign === 'right' && !!header;

Expand Down
2 changes: 1 addition & 1 deletion src/table/base/cell.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ export default class Cell extends React.Component {
className={`${prefix}table-cell-wrapper`}
style={innerStyle}
>
{content}
{children}
{content}
</div>
</Tag>
);
Expand Down
1 change: 1 addition & 0 deletions src/table/base/row.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export default class Row extends React.Component {
alignHeader,
width,
colSpan,
style,
...others
} = child;
// colSpan should show in body td by the way of <Table.Column colSpan={2} />
Expand Down
3 changes: 3 additions & 0 deletions src/table/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,9 @@
display: inline-block;
vertical-align: middle;
line-height: 1;
&:focus {
outline: 0;
}
.#{$css-prefix}icon {
position: absolute;
left: 0;
Expand Down
2 changes: 1 addition & 1 deletion src/table/virtual.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export default function virtual(BaseComponent) {
// try get cell height;
end = 1;
} else {
visibleCount = parseInt(height / rowHeight, 10);
visibleCount = parseInt(dom.getPixels(height) / rowHeight, 10);

if ('number' === typeof ExpectStart) {
start = ExpectStart < len ? ExpectStart : 0;
Expand Down
27 changes: 27 additions & 0 deletions src/util/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,30 @@ export function getOffset(node) {
left: rect.left + win.pageXOffset,
};
}

/**
* 获取不同单位转为 number 的长度
* @param {string|number} len 传入的长度
* @return {number} pixels
*/
export function getPixels(len) {
const win = document.defaultView;
if (typeof +len === 'number' && !isNaN(+len)) {
return +len;
}

if (typeof len === 'string') {
const PX_REG = /(\d+)px/;
const VH_REG = /(\d+)vh/;
if (Array.isArray(len.match(PX_REG))) {
return +len.match(PX_REG)[1] || 0;
}

if (Array.isArray(len.match(VH_REG))) {
const _1vh = win.innerHeight / 100;
return +(len.match(VH_REG)[1] * _1vh) || 0;
}
}

return 0;
}
42 changes: 42 additions & 0 deletions test/menu/index-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,48 @@ describe('Menu', () => {
document.body.removeChild(div);

});

it('should support hozInLine with header&footer in hoz', () => {

const div = document.createElement('div');
document.body.appendChild(div);

ReactDOM.render(
<Menu
direction="hoz"
style={{width: 300}}
mode="popup"
header="header"
footer="footer"
hozInLine
>
<Item key="0" style={{width: 100}}>0</Item>
<Item key="1" style={{width: 60}}>1</Item>
<SubMenu key="sub-menu" label="Sub menu" style={{width: 50}}>
<Item key="2">2</Item>
<Item key="3">3</Item>
</SubMenu>
<Item key="4" style={{width: 30}}>4</Item>
<Item key="5">5</Item>
<Item key="6">6</Item>
</Menu>,
div
);

const menu = document.querySelector('.next-menu.next-hoz');
assert(menu.querySelectorAll('li.next-menu-more').length === 2);

const indicator = menu.querySelectorAll('li.next-menu-more')[0].querySelector('.next-menu-item-inner');
indicator.click();
const overlay = document.querySelector('.next-overlay-wrapper');

assert(overlay);
assert(overlay.querySelectorAll('li').length === 3);

ReactDOM.unmountComponentAtNode(div);
document.body.removeChild(div);

});
});

describe('Menu.create', () => {
Expand Down
8 changes: 5 additions & 3 deletions test/table/issue-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,14 +338,16 @@ describe('Issue', () => {
const div = document.createElement('div');
document.body.appendChild(div);
ReactDOM.render(
<Table dataSource={[{ id: 1 }, { id: 2 }]} hasHeader={false}>
<Table dataSource={[{ id: 1 }, { id: 2 }]}>
<Table.Column dataIndex="id" style={{ textAlign: 'left' }} />
</Table>,
div
);
assert(
div.querySelectorAll('.next-table table td')[0].style.textAlign ===
'left'
div.querySelectorAll('.next-table table td')[0].style.textAlign === ''
);
assert(
div.querySelectorAll('.next-table table th')[0].style.textAlign === 'left'
);
ReactDOM.unmountComponentAtNode(div);
document.body.removeChild(div);
Expand Down
9 changes: 9 additions & 0 deletions test/util/dom-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,13 @@ describe('src/dom.js', function() {
assert(offset.left === 100);
});
});

describe('#getPixels', function() {
it('getPixels() should return number', function() {
assert(dom.getPixels('100') === 100);
assert(dom.getPixels(100) === 100);
assert(dom.getPixels('60px') === 60);
assert(dom.getPixels('100vh') === document.defaultView.innerHeight);
});
});
});

0 comments on commit 29b0d63

Please sign in to comment.