Skip to content

Commit 51be302

Browse files
committed
fix(core): adopt latest changes for user menu
1 parent c66ff14 commit 51be302

17 files changed

+748
-134
lines changed
Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
import { Component, ElementRef, ViewChild } from '@angular/core';
22
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
3+
import { By } from '@angular/platform-browser';
34
import { ListModule } from '../list.module';
5+
import { ListTitleDirective } from './list-title.directive';
46

57
@Component({
6-
template: ` <li #componentElement fd-list-title>ListTitleComponent</li> `,
8+
template: `<li #componentElement fd-list-title [truncate]="isTruncate" [wrap]="isWrap">ListTitleComponent</li>`,
79
standalone: true,
810
imports: [ListModule]
911
})
1012
class TestComponent {
1113
@ViewChild('componentElement', { read: ElementRef })
12-
ref: ElementRef;
14+
ref!: ElementRef;
15+
16+
isTruncate = false;
17+
isWrap = false;
1318
}
1419

15-
describe('ListTitleComponent', () => {
20+
describe('ListTitleDirective', () => {
1621
let component: TestComponent;
1722
let fixture: ComponentFixture<TestComponent>;
23+
let directiveInstance: ListTitleDirective;
1824

1925
beforeEach(waitForAsync(() => {
2026
TestBed.configureTestingModule({
@@ -26,13 +32,36 @@ describe('ListTitleComponent', () => {
2632
fixture = TestBed.createComponent(TestComponent);
2733
component = fixture.componentInstance;
2834
fixture.detectChanges();
35+
36+
const debugElement = fixture.debugElement.query(By.directive(ListTitleDirective));
37+
directiveInstance = debugElement.injector.get(ListTitleDirective);
2938
});
3039

3140
it('should create', () => {
3241
expect(component).toBeTruthy();
42+
expect(directiveInstance).toBeTruthy();
43+
});
44+
45+
it('should assign base class', () => {
46+
expect(component.ref.nativeElement.classList).toContain('fd-list__title');
47+
});
48+
49+
it('should not have truncate or wrap classes by default', () => {
50+
expect(component.ref.nativeElement.classList).not.toContain('fd-list__title--truncate');
51+
expect(component.ref.nativeElement.classList).not.toContain('fd-list__title--wrap');
3352
});
3453

35-
it('should assign class', () => {
36-
expect(component.ref.nativeElement.className).toBe('fd-list__title');
54+
it('should add truncate class when truncate is true (via input binding)', () => {
55+
component.isTruncate = true;
56+
fixture.detectChanges();
57+
58+
expect(component.ref.nativeElement.classList).toContain('fd-list__title--truncate');
59+
});
60+
61+
it('should add wrap class when wrap is true (via input binding)', () => {
62+
component.isWrap = true;
63+
fixture.detectChanges();
64+
65+
expect(component.ref.nativeElement.classList).toContain('fd-list__title--wrap');
3766
});
3867
});

libs/core/list/directives/list-title.directive.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
import { Directive, ElementRef, HostBinding, Input, OnInit } from '@angular/core';
1+
import { booleanAttribute, Directive, ElementRef, input, OnInit } from '@angular/core';
22

33
@Directive({
44
selector: '[fd-list-title], [fdListTitle]',
5-
standalone: true
5+
standalone: true,
6+
host: {
7+
class: 'fd-list__title',
8+
'[class.fd-list__title--truncate]': 'truncate()',
9+
'[class.fd-list__title--wrap]': 'wrap()'
10+
}
611
})
712
export class ListTitleDirective implements OnInit {
8-
/** @hidden */
9-
@HostBinding('class.fd-list__title')
10-
fdListTitleClass = true;
11-
1213
/** Whether or not this should be wrapped, when too much text. */
13-
@Input()
14-
@HostBinding('class.fd-list__title--wrap')
15-
wrap = false;
14+
wrap = input(false, { transform: booleanAttribute });
15+
16+
/** Whether the text should truncate with ellipsis. */
17+
truncate = input(false, { transform: booleanAttribute });
1618

1719
/** @hidden */
1820
constructor(public elRef: ElementRef) {}
Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
import { Component, ElementRef, ViewChild } from '@angular/core';
22
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
3+
import { By } from '@angular/platform-browser';
34
import { ListSublineDirective } from './list-subline.directive';
45

56
@Component({
6-
template: ` <li #componentElement fd-list-subline>List Subline Directive Test</li> `,
7+
template: `<li #componentElement fd-list-subline [truncate]="isTruncate">List Subline Directive Test</li>`,
78
standalone: true,
89
imports: [ListSublineDirective]
910
})
1011
class TestComponent {
1112
@ViewChild('componentElement', { read: ElementRef })
12-
ref: ElementRef;
13+
ref!: ElementRef;
14+
15+
isTruncate = false;
1316
}
1417

1518
describe('ListSublineDirective', () => {
1619
let component: TestComponent;
1720
let fixture: ComponentFixture<TestComponent>;
21+
let directiveInstance: ListSublineDirective;
1822

1923
beforeEach(waitForAsync(() => {
2024
TestBed.configureTestingModule({
@@ -26,13 +30,29 @@ describe('ListSublineDirective', () => {
2630
fixture = TestBed.createComponent(TestComponent);
2731
component = fixture.componentInstance;
2832
fixture.detectChanges();
33+
34+
// Get the directive instance
35+
const debugElement = fixture.debugElement.query(By.directive(ListSublineDirective));
36+
directiveInstance = debugElement.injector.get(ListSublineDirective);
2937
});
3038

3139
it('should create', () => {
3240
expect(component).toBeTruthy();
41+
expect(directiveInstance).toBeTruthy();
42+
});
43+
44+
it('should assign base class', () => {
45+
expect(component.ref.nativeElement.classList).toContain('fd-list__subline');
3346
});
3447

35-
it('should assign class', () => {
36-
expect(component.ref.nativeElement.className).toBe('fd-list__subline');
48+
it('should not have truncate class by default', () => {
49+
expect(component.ref.nativeElement.classList).not.toContain('fd-list__subline--truncate');
50+
});
51+
52+
it('should add truncate class when truncate is true (via input binding)', () => {
53+
component.isTruncate = true;
54+
fixture.detectChanges();
55+
56+
expect(component.ref.nativeElement.classList).toContain('fd-list__subline--truncate');
3757
});
3858
});
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
import { Directive } from '@angular/core';
1+
import { booleanAttribute, Directive, input } from '@angular/core';
22

33
@Directive({
44
selector: '[fdListSubline], [fd-list-subline]',
55
host: {
6-
class: 'fd-list__subline'
6+
class: 'fd-list__subline',
7+
'[class.fd-list__subline--truncate]': 'truncate()'
78
},
89
standalone: true
910
})
10-
export class ListSublineDirective {}
11+
export class ListSublineDirective {
12+
/** Whether the text should truncate with ellipsis. */
13+
truncate = input(false, { transform: booleanAttribute });
14+
}

libs/core/list/list.component.scss

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,59 @@
1919
.fd-list.fd-list--selection .fd-radio:focus + .fd-radio__label {
2020
outline: none;
2121
}
22+
23+
/*
24+
* TO BE REMOVED WITH FUNDAMENTAL STYLES VERSION 0.41.0
25+
* ----------------------------------------------------------------------------------------------------
26+
*/
27+
28+
.fd-list--subline .fd-list__item {
29+
height: auto;
30+
}
31+
32+
.fd-list--subline .fd-list__title {
33+
width: 100%;
34+
max-width: 100%;
35+
font-style: normal;
36+
line-height: normal;
37+
white-space: normal;
38+
font-size: var(--sapFontSize);
39+
color: var(--sapList_TextColor);
40+
font-family: var(--sapFontSemiboldDuplexFamily);
41+
}
42+
43+
.fd-list--subline .fd-list__title--truncate {
44+
white-space: nowrap;
45+
overflow: hidden;
46+
text-overflow: ellipsis;
47+
}
48+
49+
.fd-list--subline .fd-list__subline {
50+
font-size: var(--sapFontSize);
51+
line-height: normal;
52+
color: var(--sapTextColor);
53+
font-family: var(--sapFontFamily);
54+
font-weight: normal;
55+
-webkit-box-sizing: border-box;
56+
box-sizing: border-box;
57+
forced-color-adjust: none;
58+
padding-inline: 0;
59+
padding-block: 0;
60+
margin-inline: 0;
61+
margin-block: 0;
62+
border: 0;
63+
width: 100%;
64+
max-width: 100%;
65+
font-style: normal;
66+
line-height: normal;
67+
white-space: normal;
68+
font-size: var(--sapFontSize);
69+
font-family: var(--sapFontFamily);
70+
color: var(--sapContent_LabelColor);
71+
}
72+
73+
.fd-list--subline .fd-list__subline--truncate {
74+
white-space: nowrap;
75+
overflow: hidden;
76+
text-overflow: ellipsis;
77+
}

libs/core/user-menu/components/user-menu-list-item.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export class UserMenuListItemComponent implements KeyboardSupportItemInterface {
144144
this.isOpenChange.emit(isOpen);
145145

146146
this._onZoneStable().subscribe(() => {
147-
this.isOpen() ? linkElement.classList.add('is-active') : linkElement.classList.remove('is-active');
147+
this.isOpen() ? linkElement.classList.add('is-selected') : linkElement.classList.remove('is-selected');
148148
firstTabbableElement.focus();
149149
});
150150

libs/core/user-menu/directives/user-menu-subline.directive.spec.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@ import { By } from '@angular/platform-browser';
55
import { UserMenuSublineDirective } from './user-menu-subline.directive';
66

77
@Component({
8-
template: `<span fd-user-menu-subline>User Menu Subline Test</span>`,
8+
template: `<span fd-user-menu-subline [truncate]="isTruncate">User Menu Subline Test</span>`,
99
standalone: true,
1010
imports: [UserMenuSublineDirective]
1111
})
12-
class TestComponent {}
12+
class TestComponent {
13+
isTruncate = false;
14+
}
1315

1416
describe('UserMenuSublineDirective', () => {
1517
let fixture: ComponentFixture<TestComponent>;
1618
let debugElement: DebugElement;
19+
let directiveInstance: UserMenuSublineDirective;
1720

1821
beforeEach(waitForAsync(() => {
1922
TestBed.configureTestingModule({
@@ -23,17 +26,29 @@ describe('UserMenuSublineDirective', () => {
2326

2427
beforeEach(() => {
2528
fixture = TestBed.createComponent(TestComponent);
26-
2729
fixture.detectChanges();
2830

2931
debugElement = fixture.debugElement.query(By.directive(UserMenuSublineDirective));
32+
directiveInstance = debugElement.injector.get(UserMenuSublineDirective);
3033
});
3134

3235
it('should create', () => {
3336
expect(fixture).toBeTruthy();
37+
expect(directiveInstance).toBeTruthy();
38+
});
39+
40+
it('should add base class to host', () => {
41+
expect(debugElement.nativeElement.classList).toContain('fd-user-menu__subline');
3442
});
3543

36-
it('should add class to host', () => {
37-
expect(debugElement.nativeElement.className.includes('fd-user-menu__subline')).toBe(true);
44+
it('should not have truncate class by default', () => {
45+
expect(debugElement.nativeElement.classList).not.toContain('fd-user-menu__subline--truncate');
46+
});
47+
48+
it('should add truncate class when truncate is true (via input binding)', () => {
49+
fixture.componentInstance.isTruncate = true;
50+
fixture.detectChanges();
51+
52+
expect(debugElement.nativeElement.classList).toContain('fd-user-menu__subline--truncate');
3853
});
3954
});
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
import { Directive } from '@angular/core';
1+
import { booleanAttribute, Directive, input } from '@angular/core';
22

33
@Directive({
44
// eslint-disable-next-line @angular-eslint/directive-selector
55
selector: '[fd-user-menu-subline]',
66
host: {
7-
class: 'fd-user-menu__subline'
7+
class: 'fd-user-menu__subline',
8+
'[class.fd-user-menu__subline--truncate]': 'truncate()'
89
}
910
})
10-
export class UserMenuSublineDirective {}
11+
export class UserMenuSublineDirective {
12+
/** Whether the text should truncate with ellipsis. */
13+
truncate = input(false, { transform: booleanAttribute });
14+
}

libs/core/user-menu/directives/user-menu-user-name.directive.spec.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@ import { By } from '@angular/platform-browser';
55
import { UserMenuUserNameDirective } from './user-menu-user-name.directive';
66

77
@Component({
8-
template: `<span fd-user-menu-user-name>User Menu User Name Test</span>`,
8+
template: `<span fd-user-menu-user-name [truncate]="isTruncate">User Menu User Name Test</span>`,
99
standalone: true,
1010
imports: [UserMenuUserNameDirective]
1111
})
12-
class TestComponent {}
12+
class TestComponent {
13+
isTruncate = false;
14+
}
1315

1416
describe('UserMenuUserNameDirective', () => {
1517
let fixture: ComponentFixture<TestComponent>;
1618
let debugElement: DebugElement;
19+
let directiveInstance: UserMenuUserNameDirective;
1720

1821
beforeEach(waitForAsync(() => {
1922
TestBed.configureTestingModule({
@@ -23,17 +26,29 @@ describe('UserMenuUserNameDirective', () => {
2326

2427
beforeEach(() => {
2528
fixture = TestBed.createComponent(TestComponent);
26-
2729
fixture.detectChanges();
2830

2931
debugElement = fixture.debugElement.query(By.directive(UserMenuUserNameDirective));
32+
directiveInstance = debugElement.injector.get(UserMenuUserNameDirective);
3033
});
3134

3235
it('should create', () => {
3336
expect(fixture).toBeTruthy();
37+
expect(directiveInstance).toBeTruthy();
38+
});
39+
40+
it('should add base class to host', () => {
41+
expect(debugElement.nativeElement.classList).toContain('fd-user-menu__user-name');
3442
});
3543

36-
it('should add class to host', () => {
37-
expect(debugElement.nativeElement.className.includes('fd-user-menu__user-name')).toBe(true);
44+
it('should not have truncate class by default', () => {
45+
expect(debugElement.nativeElement.classList).not.toContain('fd-user-menu__user-name--truncate');
46+
});
47+
48+
it('should add truncate class when truncate is true (via input binding)', () => {
49+
fixture.componentInstance.isTruncate = true;
50+
fixture.detectChanges();
51+
52+
expect(debugElement.nativeElement.classList).toContain('fd-user-menu__user-name--truncate');
3853
});
3954
});
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
import { Directive } from '@angular/core';
1+
import { booleanAttribute, Directive, input } from '@angular/core';
22

33
@Directive({
44
// eslint-disable-next-line @angular-eslint/directive-selector
55
selector: '[fd-user-menu-user-name]',
66
host: {
7-
class: 'fd-user-menu__user-name'
7+
class: 'fd-user-menu__user-name',
8+
'[class.fd-user-menu__user-name--truncate]': 'truncate()'
89
}
910
})
10-
export class UserMenuUserNameDirective {}
11+
export class UserMenuUserNameDirective {
12+
/** Whether the text should truncate with ellipsis. */
13+
truncate = input(false, { transform: booleanAttribute });
14+
}

0 commit comments

Comments
 (0)