Skip to content

Commit 7f8a450

Browse files
authored
Merge pull request #223 from microsoftgraph/nmetulev/person-image
fix for person image not rendering, introduces selected-person template
2 parents 24c1232 + f581989 commit 7f8a450

File tree

4 files changed

+42
-34
lines changed

4 files changed

+42
-34
lines changed

src/components/mgt-people-picker/mgt-people-picker.scss

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ mgt-people-picker .people-list-separator {
6464
text-align: center;
6565
}
6666

67-
:host .people-chosen-input,
68-
mgt-people-picker .people-chosen-input {
67+
:host .people-selected-input,
68+
mgt-people-picker .people-selected-input {
6969
position: relative;
7070
border: none;
7171
line-height: normal;
@@ -77,8 +77,8 @@ mgt-people-picker .people-chosen-input {
7777
line-height: 19px;
7878
}
7979

80-
:host .people-chosen-list,
81-
mgt-people-picker .people-chosen-list {
80+
:host .people-selected-list,
81+
mgt-people-picker .people-selected-list {
8282
display: flex;
8383
flex-wrap: wrap;
8484
vertical-align: middle;
@@ -113,7 +113,6 @@ mgt-people-picker .people-person {
113113
border-radius: 15px;
114114
height: 24px;
115115
white-space: nowrap;
116-
overflow: hidden;
117116
text-overflow: ellipsis;
118117
}
119118

@@ -192,7 +191,6 @@ mgt-people-picker .remove-person-button-secondary {
192191
mgt-people-picker .person-display-name {
193192
max-width: 100px;
194193
white-space: nowrap;
195-
overflow: hidden;
196194
text-overflow: ellipsis;
197195
margin-left: 8px;
198196
font-family: Segoe UI;
@@ -207,8 +205,9 @@ mgt-people-picker .person-display-name {
207205
mgt-person {
208206
--avatar-size-s: 32px;
209207
margin-left: 12px;
208+
cursor: default;
210209
}
211-
.chosen-person {
210+
.selected-person {
212211
--avatar-size-s: 24px;
213212
margin-left: 0px;
214213
}

src/components/mgt-people-picker/mgt-people-picker.ts

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
129129
html`
130130
<div class="people-picker" @blur=${this.lostFocus}>
131131
<div class="people-picker-input" @click=${this.gainedFocus}>
132-
${this.renderChosenPeople()}
132+
${this.renderSelectedPeople()}
133133
</div>
134134
<div class="people-list-separator"></div>
135135
${this.renderPeopleList()}
@@ -145,7 +145,7 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
145145
* @memberof MgtPeoplePicker
146146
*/
147147
public focus(options?: FocusOptions) {
148-
const peopleInput = this.renderRoot.querySelector('.people-chosen-input') as HTMLInputElement;
148+
const peopleInput = this.renderRoot.querySelector('.people-selected-input') as HTMLInputElement;
149149
if (peopleInput) {
150150
peopleInput.focus(options);
151151
}
@@ -378,9 +378,8 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
378378
* @param person - person and details pertaining to user selected
379379
*/
380380
private removePerson(person: MicrosoftGraph.User | MicrosoftGraph.Person | MicrosoftGraph.Contact) {
381-
const chosenPerson: any = person;
382381
const filteredPersonArr = this.selectedPeople.filter(p => {
383-
return p.id !== chosenPerson.id;
382+
return p.id !== person.id;
384383
});
385384
this.selectedPeople = filteredPersonArr;
386385
this.fireCustomEvent('selectionChanged', this.selectedPeople);
@@ -406,7 +405,7 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
406405
`;
407406
}
408407

409-
private renderChosenPeople() {
408+
private renderSelectedPeople() {
410409
let peopleList;
411410
let inputClass = 'input-search-start';
412411
if (this.selectedPeople.length > 0) {
@@ -416,10 +415,11 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
416415
${this.selectedPeople.slice(0, this.selectedPeople.length).map(
417416
person =>
418417
html`
419-
<li class="people-person">
420-
${this.renderTemplate('person', { person }, person.displayName) || this.renderChosenPerson(person)}
418+
<div class="people-person">
419+
${this.renderTemplate('selected-person', { person }, `selected-${person.id}`) ||
420+
this.renderSelectedPerson(person)}
421421
<div class="CloseIcon" @click="${() => this.removePerson(person)}">\uE711</div>
422-
</li>
422+
</div>
423423
`
424424
)}
425425
`;
@@ -428,12 +428,12 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
428428
}
429429
// tslint:disable
430430
return html`
431-
<div class="people-chosen-list">
431+
<div class="people-selected-list">
432432
${peopleList}
433433
<div class="${inputClass}">
434434
<input
435435
id="people-picker-input"
436-
class="people-chosen-input"
436+
class="people-selected-input"
437437
type="text"
438438
placeholder="Start typing a name"
439439
label="people-picker-input"
@@ -451,7 +451,7 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
451451

452452
private gainedFocus() {
453453
const peopleList = this.renderRoot.querySelector('.people-list');
454-
const peopleInput = this.renderRoot.querySelector('.people-chosen-input') as HTMLInputElement;
454+
const peopleInput = this.renderRoot.querySelector('.people-selected-input') as HTMLInputElement;
455455
peopleInput.focus();
456456
peopleInput.select();
457457
if (peopleList) {
@@ -504,13 +504,12 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
504504
}
505505

506506
private renderPeopleList() {
507-
let people: any = this.people;
508507
let content: TemplateResult;
509508

510509
if (this.showLoading) {
511510
content = this.renderTemplate('loading', null, 'loading') || this.renderLoadingMessage();
512-
} else if (people) {
513-
people = people.slice(0, this.showMax);
511+
} else if (this.people) {
512+
const people = this.people.slice(0, this.showMax);
514513

515514
if (!this.isLoading && people.length === 0 && this._userInput.length > 0) {
516515
content = this.renderTemplate('error', null, 'error') || this.renderErrorMessage();
@@ -539,11 +538,7 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
539538
class="list-person ${person.isSelected === 'fill' ? 'people-person-list-fill' : 'people-person-list'}"
540539
@click="${() => this.addPerson(person)}"
541540
>
542-
${this.renderTemplate('person', { person }, person.displayName) || this.renderPerson(person)}
543-
<div class="people-person-text-area" id="${person.displayName}">
544-
${this.renderHighlightText(person)}
545-
<span class="people-person-job-title">${person.jobTitle}</span>
546-
</div>
541+
${this.renderTemplate('person', { person }, person.id) || this.renderPerson(person)}
547542
</li>
548543
`
549544
)}
@@ -553,11 +548,21 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
553548
private renderPerson(person: MicrosoftGraph.Person) {
554549
return html`
555550
<mgt-person .personDetails=${person} .personImage=${'@'}></mgt-person>
551+
<div class="people-person-text-area" id="${person.displayName}">
552+
${this.renderHighlightText(person)}
553+
<span class="people-person-job-title">${person.jobTitle}</span>
554+
</div>
556555
`;
557556
}
558-
private renderChosenPerson(person: MicrosoftGraph.Person) {
557+
private renderSelectedPerson(person: MicrosoftGraph.Person) {
559558
return html`
560-
<mgt-person class="chosen-person" .personDetails=${person} .personImage=${'@'} show-name></mgt-person>
559+
<mgt-person
560+
class="selected-person"
561+
.personDetails=${person}
562+
.personImage=${'@'}
563+
show-name
564+
person-card="click"
565+
></mgt-person>
561566
`;
562567
}
563568
}

src/components/mgt-person-card/mgt-person-card.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ $color: var(--color, #{$ms-color-neutralDark});
2727

2828
.details {
2929
margin-left: 14px;
30+
line-height: 1.15;
3031

3132
.display-name {
3233
font-size: 27.3103px;
@@ -56,6 +57,7 @@ $color: var(--color, #{$ms-color-neutralDark});
5657

5758
.icon {
5859
margin: 0 22px 0 0;
60+
cursor: pointer;
5961
}
6062
.icon:hover {
6163
opacity: 0.6;
@@ -118,6 +120,7 @@ $color: var(--color, #{$ms-color-neutralDark});
118120
}
119121
.link-subtitle {
120122
color: #3078cd;
123+
cursor: pointer;
121124
}
122125
.link-subtitle:hover {
123126
opacity: 0.6;

src/components/mgt-person/mgt-person.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export class MgtPerson extends MgtTemplatedComponent {
9393
*/
9494
@property({
9595
attribute: 'person-image',
96+
reflect: true,
9697
type: String
9798
})
9899
public personImage: string;
@@ -122,8 +123,6 @@ export class MgtPerson extends MgtTemplatedComponent {
122123

123124
private _mouseLeaveTimeout;
124125
private _mouseEnterTimeout;
125-
private _openLeft: boolean = false;
126-
private _openUp: boolean = false;
127126

128127
/**
129128
* Synchronizes property values when attributes change.
@@ -163,11 +162,12 @@ export class MgtPerson extends MgtTemplatedComponent {
163162
* trigger the element to update.
164163
*/
165164
public render() {
165+
const image = this.getImage();
166166
const person =
167-
this.renderTemplate('default', { person: this.personDetails, personImage: this.getImage() }) ||
167+
this.renderTemplate('default', { person: this.personDetails, personImage: image }) ||
168168
html`
169169
<div class="person-root">
170-
${this.renderImage()} ${this.renderDetails()}
170+
${this.renderImage(image)} ${this.renderDetails()}
171171
</div>
172172
`;
173173

@@ -240,6 +240,7 @@ export class MgtPerson extends MgtTemplatedComponent {
240240
const response = await batch.execute();
241241

242242
this.personDetails = response.user;
243+
this.personImage = response.photo;
243244
(this.personDetails as any).personImage = response.photo;
244245
} else if (!this.personDetails && this.personQuery) {
245246
const people = await provider.graph.findPerson(this.personQuery);
@@ -280,6 +281,7 @@ export class MgtPerson extends MgtTemplatedComponent {
280281
}
281282
}
282283
if (image) {
284+
this.personImage = image;
283285
(this.personDetails as any).personImage = image;
284286
}
285287

@@ -378,10 +380,9 @@ export class MgtPerson extends MgtTemplatedComponent {
378380
return null;
379381
}
380382

381-
private renderImage() {
383+
private renderImage(image: string) {
382384
if (this.personDetails) {
383385
const title = this.personCardInteraction === PersonCardInteraction.none ? this.personDetails.displayName : '';
384-
const image = this.getImage();
385386
const isLarge = this.showEmail && this.showName;
386387
const imageClasses = {
387388
initials: !image,

0 commit comments

Comments
 (0)