Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions all.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import './buttons/button.js'
import './buttons/filled-tonal-button.js'
import './buttons/outlined-button.js'
import './buttons/text-button.js'
import './carousel/carousel.js'
import './carousel/carousel-item.js'
import './checkbox/checkbox.js'
import './chips/assist-chip.js'
import './chips/chip-set.js'
Expand Down Expand Up @@ -48,6 +50,8 @@ import './text/text-field.js'
// LINT.IfChange(exports)
// go/keep-sorted start
export * from './buttons/button.js'
export * from './carousel/carousel.js'
export * from './carousel/carousel-item.js'
export * from './checkbox/checkbox.js'
export * from './chips/chip.js'
export * from './chips/chip-set.js'
Expand Down
27 changes: 27 additions & 0 deletions carousel/carousel-item.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { LitElement, html, css } from 'lit'

export class CarouselItem extends LitElement {
constructor() {
super()
this.internals = this.attachInternals()
this.internals.role = 'listitem'
}

static styles = [
css`
:host {
display: flex;
flex-shrink: 0;
scroll-snap-align: start;
border-radius: var(--md-carousel-item-shape, 28px);
overflow: hidden;
}
`,
]

render() {
return html`<slot></slot>`
}
}

customElements.define('md-carousel-item', CarouselItem)
32 changes: 32 additions & 0 deletions carousel/carousel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { LitElement, html, css } from 'lit'

export class Carousel extends LitElement {
constructor() {
super()
this.internals = this.attachInternals()
this.internals.role = 'list'
Comment on lines +6 to +7
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The carousel container is scrollable but lacks keyboard focusability, which prevents users who rely on arrow keys from navigating the content. Additionally, explicitly setting the aria-orientation helps assistive technologies correctly interpret the component's layout.

    this.internals = this.attachInternals()
    this.internals.role = 'list'
    this.internals.ariaOrientation = 'horizontal'
    this.tabIndex = 0

}

static styles = [
css`
:host {
display: flex;
overflow-x: auto;
scroll-snap-type: x mandatory;
scrollbar-width: none; /* Firefox */
gap: var(--md-carousel-gap, 8px);
padding: var(--md-carousel-padding, 16px);
}

:host::-webkit-scrollbar {
display: none; /* Safari and Chrome */
}
`,
]

render() {
return html`<slot></slot>`
}
}

customElements.define('md-carousel', Carousel)
4 changes: 4 additions & 0 deletions common.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* for production.
*/
import './buttons/button.js'
import './carousel/carousel.js'
import './carousel/carousel-item.js'
import './checkbox/checkbox.js'
import './chips/chip.js'
import './chips/chip-set.js'
Expand All @@ -27,6 +29,8 @@ import './tabs/tabs.js'
import './text/text-field.js'

export * from './buttons/button.js'
export * from './carousel/carousel.js'
export * from './carousel/carousel-item.js'
export * from './checkbox/checkbox.js'
export * from './chips/chip.js'
export * from './chips/chip-set.js'
Expand Down