From 2b074ef5605b7fe844855836d6500ee8a44ead02 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Fri, 12 Jan 2018 16:06:59 +0100 Subject: [PATCH] fix(list): incorrect padding for list-items with avatars, icons (#9163) Currently list-items with an avatar, icon or checkbox have a both-sided margin for the text of 16px, while there is still a padding of 16px for the `mat-list-item-content` of 16px. This means that there is a 32px padding, that is not valid per specs. The padding for the mat-list-text should be just on the side of the secondary item (e.g. avatar, icon or checkbox), and the other side should have no padding, because the `mat-list-item-content` already has a padding for that one. Fixes #9156 --- src/demo-app/list/list-demo.html | 2 +- src/lib/list/list.scss | 33 +++++++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/demo-app/list/list-demo.html b/src/demo-app/list/list-demo.html index d3f3a87f100b..b34f72d031f1 100644 --- a/src/demo-app/list/list-demo.html +++ b/src/demo-app/list/list-demo.html @@ -110,7 +110,7 @@

Selection list

(change)="changeEventCount = changeEventCount + 1">

Groceries

- Bananas + Bananas Oranges Apples Strawberries diff --git a/src/lib/list/list.scss b/src/lib/list/list.scss index f5df574757eb..9949dfad92ae 100644 --- a/src/lib/list/list.scss +++ b/src/lib/list/list.scss @@ -90,17 +90,40 @@ $mat-dense-list-icon-size: 20px; .mat-list-text { @include mat-line-wrapper-base(); - padding: 0 $mat-list-side-padding; - // We only want to override the padding if there isn't - // an avatar or icon before the element. Since the ripple - // will always be the first child in the container, we - // check whether this element is the second child. + // By default, padding will be always added on the start-side of the mat-list-text, because + // we assume that there is always a secondary item (e.g. avatar-icon, checkbox). But if the + // mat-list-text element is the second element, then there is no secondary item and + // the padding can be removed. &:nth-child(2) { padding: 0; } } + // There can be a secondary item (e.g. avatar-icon, checkbox) at the start of the + // list-item. This means that there should be a padding for the mat-list-text on the start-side. + .mat-list-item-content .mat-list-text { + padding-left: $mat-list-side-padding; + + [dir='rtl'] & { + padding-right: $mat-list-side-padding; + padding-left: 0; + } + } + + // Reversed content is mainly used by the MatSelectionList for displaying the checkbox at the + // end of the list option. Since there is a secondary item (checkbox) at the end of the + // option, there needs to be a padding for the mat-list-text on the end-side. + .mat-list-item-content-reverse .mat-list-text { + padding-left: 0; + padding-right: $mat-list-side-padding; + + [dir='rtl'] & { + padding-right: 0; + padding-left: $mat-list-side-padding; + } + } + .mat-list-avatar { flex-shrink: 0; width: $mat-list-avatar-size;