Skip to content

Commit

Permalink
fixed missing classes in radio button and button components (#1823)
Browse files Browse the repository at this point in the history
  • Loading branch information
rengare authored and InnaAtanasova committed Jan 16, 2020
1 parent 673e618 commit 5aed6a2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ import { ELEMENT_REF_EXCEPTION } from '../public_api';
*/
export function applyCssClass(target: any, propertyKey: string, descriptor: PropertyDescriptor): void {
const originalMethod = descriptor.value;
descriptor.value = function (): string {
descriptor.value = function(): string {
if (!this.elementRef) {
throw ELEMENT_REF_EXCEPTION;
}

const _class = originalMethod.apply(this);
const elementRef = this.elementRef();
const elementRef = this.elementRef.apply(this);

if (elementRef) {
(elementRef.nativeElement as HTMLElement).classList.value = `${_class} ${this.class ? this.class : ''}`;
(elementRef.nativeElement as HTMLElement).className = `${_class} ${this.class ? this.class : ''}`;
}

return _class;
Expand Down
14 changes: 10 additions & 4 deletions libs/core/src/lib/utils/decorators/apply-css-style.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,21 @@ import { Hash, ELEMENT_REF_EXCEPTION } from '../public_api';
*/
export function applyCssStyle(target: any, propertyKey: string, descriptor: PropertyDescriptor): void {
const originalMethod = descriptor.value;
descriptor.value = function (): Hash<number | string> {
if (!this.elementRef) { throw ELEMENT_REF_EXCEPTION; }
descriptor.value = function(): Hash<number | string> {
if (!this.elementRef) {
throw ELEMENT_REF_EXCEPTION;
}

const _styles: Hash<number | string> = originalMethod.apply(this);
if (!this.elementRef()) {
return;
}

const htmlElement = this.elementRef().nativeElement as HTMLElement;
Object.keys(_styles).forEach(key => {
(this.elementRef().nativeElement as HTMLElement).style[key] = _styles[key];
htmlElement.style[key] = _styles[key];
});

return _styles;
}
};
}

0 comments on commit 5aed6a2

Please sign in to comment.