Skip to content

Commit cbfcd33

Browse files
khmakotomsft-github-bot
authored andcommitted
Stack: Modifying StackItem so that it can render multiple children (#7908)
* Removing children prop from StackItem.types.ts as it is already given to StackItem via IComponent. * Stack: Modifying StackItem so that it can handle multiple children. * Adding change file. * Removing childNodes variable that is unused.
1 parent 7390c75 commit cbfcd33

5 files changed

Lines changed: 81 additions & 76 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@uifabric/experiments",
5+
"comment": "Stack: Modifying StackItem so that it can render multiple children.",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@uifabric/experiments",
10+
"email": "makotom@microsoft.com"
11+
}

packages/experiments/src/components/Stack/StackItem/StackItem.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ describe('Stack Item', () => {
6161
</Stack>
6262
);
6363

64-
const stackItem = wrapper.find('span').at(0);
64+
const stackItem = wrapper.find('div').at(1);
6565
const stackItemClass = stackItem.props().className;
66-
const child = wrapper.find('span').at(1);
66+
const child = wrapper.find('span').at(0);
6767
const childClass = child.props().className;
6868

6969
expect(stackItemClass).toContain(stackItemClassName);

packages/experiments/src/components/Stack/StackItem/StackItem.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@ import { IStackItemComponent, IStackItemProps, IStackItemSlots } from './StackIt
55
import { styles } from './StackItem.styles';
66

77
const view: IStackItemComponent['view'] = props => {
8-
const childNodes: React.ReactElement<{}>[] = React.Children.toArray(props.children) as React.ReactElement<{}>[];
9-
const first = childNodes[0];
10-
if (!first) {
8+
const { children } = props;
9+
if (React.Children.count(children) < 1) {
1110
return null;
1211
}
1312

1413
const Slots = getSlots<IStackItemProps, IStackItemSlots>(props, {
15-
root: 'span'
14+
root: 'div'
1615
});
1716

18-
return <Slots.root>{first}</Slots.root>;
17+
return <Slots.root>{children}</Slots.root>;
1918
};
2019

2120
export const StackItem: React.StatelessComponent<IStackItemProps> = createComponent({

packages/experiments/src/components/Stack/StackItem/StackItem.types.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ export interface IStackItemProps extends IStackItemSlots, IStyleableComponentPro
2323
*/
2424
className?: string;
2525

26-
/**
27-
* @internal Internal use only - gives the Stack component a handle on the children of its Stack.Items
28-
*/
29-
children?: (React.ReactElement<IStackItemProps> | string)[] | React.ReactElement<IStackItemProps> | string;
30-
3126
/**
3227
* Defines how much to grow the StackItem in proportion to its siblings.
3328
*/

0 commit comments

Comments
 (0)