Skip to content

Commit

Permalink
fix(button): make sure icon has margins when button has html co… (#1953)
Browse files Browse the repository at this point in the history
  • Loading branch information
nnixaa committed Sep 11, 2019
1 parent 2f427be commit a17accb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/framework/theme/components/button/button.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
import { NbComponentStatus } from '../component-status';
import { NbComponentShape } from '../component-shape';
import { NbComponentSize } from '../component-size';
import { convertToBoolProperty } from '../helpers';
import { convertToBoolProperty, firstChildNotComment, lastChildNotComment } from '../helpers';

export type NbButtonAppearance = 'filled' | 'outline' | 'ghost' | 'hero';

Expand Down Expand Up @@ -528,14 +528,14 @@ export class NbButtonComponent implements AfterViewInit {
get iconLeft(): boolean {
const el = this.hostElement.nativeElement;
const icon = this.iconElement;
return !!(icon && el.firstChild === icon);
return !!(icon && firstChildNotComment(el) === icon);
}

@HostBinding('class.icon-end')
get iconRight(): boolean {
const el = this.hostElement.nativeElement;
const icon = this.iconElement;
return !!(icon && el.lastChild === icon);
return !!(icon && lastChildNotComment(el) === icon);
}

@HostBinding('class.transitions')
Expand Down
13 changes: 13 additions & 0 deletions src/framework/theme/components/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,16 @@ export function getElementHeight(el) {
return el.offsetHeight + marginTop + marginBottom;
}

export function firstChildNotComment(node: Node) {
const children = Array
.from(node.childNodes)
.filter((child: Node) => child.nodeType !== Node.COMMENT_NODE);
return children[0];
}

export function lastChildNotComment(node: Node) {
const children = Array
.from(node.childNodes)
.filter((child: Node) => child.nodeType !== Node.COMMENT_NODE);
return children[children.length - 1];
}

0 comments on commit a17accb

Please sign in to comment.