- ${!this.value?.media_content_id
- ? this.hass.localize(
- "ui.components.selectors.media.pick_media"
- )
- : this.value.metadata?.title || this.value.media_content_id}
+
+
+ ${this.value?.metadata?.thumbnail
+ ? html`
+
+ `
+ : html`
+
+
+
+ `}
+
+
+ ${!this.value?.media_content_id
+ ? this.hass.localize(
+ "ui.components.selectors.media.pick_media"
+ )
+ : this.value.metadata?.title || this.value.media_content_id}
+
`}
@@ -229,6 +232,13 @@ export class HaMediaSelector extends LitElement {
});
}
+ private _handleKeyDown(ev: KeyboardEvent) {
+ if (ev.key === "Enter" || ev.key === " ") {
+ ev.preventDefault();
+ this._pickMedia();
+ }
+ }
+
static styles = css`
ha-entity-picker {
display: block;
@@ -243,41 +253,52 @@ export class HaMediaSelector extends LitElement {
}
ha-card {
position: relative;
- width: 200px;
+ width: 100%;
box-sizing: border-box;
cursor: pointer;
+ transition: background-color 180ms ease-in-out;
+ min-height: 56px;
+ }
+ ha-card:hover:not(.disabled),
+ ha-card:focus:not(.disabled) {
+ background-color: var(--state-icon-hover-color, rgba(0, 0, 0, 0.04));
+ }
+ ha-card:focus {
+ outline: none;
}
ha-card.disabled {
pointer-events: none;
color: var(--disabled-text-color);
}
+ .content-container {
+ display: flex;
+ align-items: center;
+ padding: 8px;
+ gap: 12px;
+ }
ha-card .thumbnail {
- width: 100%;
+ width: 40px;
+ height: 40px;
+ flex-shrink: 0;
position: relative;
box-sizing: border-box;
- transition: padding-bottom 0.1s ease-out;
- padding-bottom: 100%;
- }
- ha-card .thumbnail.portrait {
- padding-bottom: 150%;
+ border-radius: 8px;
+ overflow: hidden;
}
ha-card .image {
- border-radius: 3px 3px 0 0;
+ border-radius: 8px;
}
.folder {
- --mdc-icon-size: calc(var(--media-browse-item-size, 175px) * 0.4);
+ --mdc-icon-size: 24px;
}
.title {
- font-size: var(--ha-font-size-l);
- padding-top: 16px;
+ font-size: var(--ha-font-size-m);
overflow: hidden;
text-overflow: ellipsis;
- margin-bottom: 16px;
- padding-left: 16px;
- padding-right: 4px;
- padding-inline-start: 16px;
- padding-inline-end: 4px;
white-space: nowrap;
+ line-height: 1.4;
+ flex: 1;
+ min-width: 0;
}
.image {
position: absolute;
@@ -290,13 +311,15 @@ export class HaMediaSelector extends LitElement {
background-position: center;
}
.centered-image {
- margin: 0 8px;
+ margin: 4px;
background-size: contain;
}
.icon-holder {
display: flex;
justify-content: center;
align-items: center;
+ width: 100%;
+ height: 100%;
}
`;
}