Skip to content

Commit

Permalink
refactor(panel, shell, tree-item): Add keys to conditionally rendered…
Browse files Browse the repository at this point in the history
… slots. (#3962)

* refactor(panel, shell, tree-item): Add keys to conditionally rendered slots.

* add const for key.

* fix code

* review cleanup
  • Loading branch information
driskull authored and Yona Nagayama committed Jan 24, 2022
1 parent a2738e4 commit e59ccc7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
11 changes: 7 additions & 4 deletions src/components/calcite-panel/calcite-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -399,24 +399,27 @@ export class CalcitePanel implements ConditionalSlotComponent {
const { el } = this;
const hasFab = getSlotted(el, SLOTS.fab);

const defaultSlotNode: VNode = <slot key="default-slot" />;
const contentWrapperKey = "content-wrapper";

return hasFab ? (
<div
class={{ [CSS.contentWrapper]: true, [CSS.contentHeight]: true }}
key={contentWrapperKey}
onScroll={this.panelScrollHandler}
tabIndex={0}
>
<section class={CSS.contentContainer}>
<slot />
</section>
<section class={CSS.contentContainer}>{defaultSlotNode}</section>
{this.renderFab()}
</div>
) : (
<section
class={{ [CSS.contentWrapper]: true, [CSS.contentContainer]: true }}
key={contentWrapperKey}
onScroll={this.panelScrollHandler}
tabIndex={0}
>
<slot />
{defaultSlotNode}
</section>
);
}
Expand Down
17 changes: 11 additions & 6 deletions src/components/calcite-shell/calcite-shell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,27 @@ export class CalciteShell implements ConditionalSlotComponent {
}

renderContent(): VNode[] {
const defaultSlotNode: VNode = <slot key="default-slot" />;
const centerRowSlotNode: VNode = <slot key="center-row-slot" name={SLOTS.centerRow} />;
const contentContainerKey = "content-container";

const content = !!this.contentBehind
? [
<div
class={{
[CSS.content]: true,
[CSS.contentBehind]: !!this.contentBehind
[CSS.contentBehind]: true
}}
key={contentContainerKey}
>
<slot />
{defaultSlotNode}
</div>,
<slot name={SLOTS.centerRow} />
centerRowSlotNode
]
: [
<div class={CSS.content}>
<slot />
<slot name={SLOTS.centerRow} />
<div class={CSS.content} key={contentContainerKey}>
{defaultSlotNode}
{centerRowSlotNode}
</div>
];

Expand Down
7 changes: 4 additions & 3 deletions src/components/calcite-tree-item/calcite-tree-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,10 @@ export class CalciteTreeItem implements ConditionalSlotComponent {
scale="s"
/>
) : null;
const defaultSlotNode: VNode = <slot key="default-slot" />;
const checkbox =
this.selectionMode === TreeSelectionMode.Ancestors ? (
<label class={CSS.checkboxLabel}>
<label class={CSS.checkboxLabel} key="checkbox-label">
<calcite-checkbox
checked={this.selected}
class={CSS.checkbox}
Expand All @@ -169,7 +170,7 @@ export class CalciteTreeItem implements ConditionalSlotComponent {
scale={this.scale}
tabIndex={-1}
/>
<slot />
{defaultSlotNode}
</label>
) : null;
const selectedIcon = showBulletPoint
Expand Down Expand Up @@ -210,7 +211,7 @@ export class CalciteTreeItem implements ConditionalSlotComponent {
>
{chevron}
{bulletOrCheckIcon}
{checkbox ? checkbox : <slot />}
{checkbox ? checkbox : defaultSlotNode}
</div>
<div
class={{
Expand Down

0 comments on commit e59ccc7

Please sign in to comment.