Compare commits

..

1 Commits

Author SHA1 Message Date
Cory LaViska
65ab56c6ca use <sl-copy-button> 2023-08-22 15:59:37 -04:00
69 changed files with 189 additions and 924 deletions

View File

@@ -137,17 +137,15 @@
<tr>
<td>
<code class="nowrap">{{ prop.name }}</code>
{% if prop.attribute | length > 0 %}
{% if prop.attribute != prop.name %}
<br>
<sl-tooltip content="This attribute is different from its property">
<small>
<code class="nowrap">
{{ prop.attribute }}
</code>
</small>
</sl-tooltip>
{% endif %}
{% if prop.attribute != prop.name %}
<br>
<sl-tooltip content="This attribute is different from its property">
<small>
<code class="nowrap">
{{ prop.attribute }}
</code>
</small>
</sl-tooltip>
{% endif %}
</td>
<td>
@@ -187,7 +185,7 @@
</tbody>
</table>
<p><em>Learn more about <a href="{{ rootUrl('/getting-started/usage#attributes-and-properties') }}">attributes and properties</a>.</em></p>
<p><em>Learn more about <a href="{{ rootUrl('/getting-started/usage#properties') }}">attributes and properties</a>.</em></p>
{% endif %}
{# Events #}
@@ -307,7 +305,7 @@
</tbody>
</table>
<p><em>Learn more about <a href="{{ rootUrl('/getting-started/customizing/#css-parts') }}">customizing CSS parts</a>.</em></p>
<p><em>Learn more about <a href="{{ rootUrl('/getting-started/usage#component-parts') }}">customizing CSS parts</a>.</em></p>
{% endif %}
{# Animations #}
@@ -331,7 +329,7 @@
</tbody>
</table>
<p><em>Learn more about <a href="{{ rootUrl('/getting-started/customizing#animations') }}">customizing animations</a>.</em></p>
<p><em>Learn more about <a href="{{ rootUrl('/getting-started/usage#animations') }}">customizing animations</a>.</em></p>
{% endif %}
{# Dependencies #}

View File

@@ -373,12 +373,4 @@
hide();
}
});
// We're using Turbo, so when a user searches for something, visits a result, and presses the back button, the search
// UI will still be visible but not interactive. This removes the search UI when Turbo renders a page so they don't
// get trapped.
window.addEventListener('turbo:render', () => {
document.body.classList.remove('search-visible');
document.querySelectorAll('.search__overlay, .search__dialog').forEach(el => el.remove());
});
})();

View File

@@ -534,7 +534,7 @@ pre .copy-code-button {
}
pre:hover .copy-code-button,
.copy-code-button:focus-within {
.copy-code-button:focus-visible {
opacity: 1;
scale: 1;
}

View File

@@ -1,67 +0,0 @@
---
meta:
title: Calendar
description: Calendar shows a monthly view of the Gregorian calendar, optionally allowing users to interact with dates.
layout: component
---
```html:preview
<sl-calendar></sl-calendar>
```
## Examples
### Month & Day Labels
Month and day labels can be customized using the `month-labels` and `day-labels` attributes. Note that month names are localized automatically based on the component's `lang` attribute, falling back to the document language.
```html:preview
<sl-calendar month-labels="short" day-labels="narrow"></sl-calendar>
```
### Showing Adjacent Dates
By default, only dates in the target month are shown. You can fill the grid with adjacent dates using the `show-adjacent-dates` attribute.
```html:preview
<sl-calendar show-adjacent-dates></sl-calendar>
```
### Date Selection
One or more dates can be selected by setting the `selectedDates` property. An array of dates is accepted and the selection does not have to be continuous.
```html:preview
<sl-calendar class="calendar-selection"></sl-calendar>
<script>
const calendar = document.querySelector('.calendar-selection');
const today = new Date();
// Set the selected date range from the 12-15 of the current month
calendar.selectedDates = [
new Date(today.getFullYear(), today.getMonth(), 12),
new Date(today.getFullYear(), today.getMonth(), 13),
new Date(today.getFullYear(), today.getMonth(), 14),
new Date(today.getFullYear(), today.getMonth(), 15)
];
</script>
```
### With Borders
To add a border, set the `--border-width` custom property. You can further customize the border with `--border-color` and `--border-radius`.
```html:preview
<sl-calendar style="--border-width: 1px;"></sl-calendar>
```
### Localizing the Calendar
By default, the calendar will use the document's locale. You can use the `lang` attribute to change this.
```html:preview
<sl-calendar lang="es"></sl-calendar>
```
[component-metadata:sl-calendar]

View File

@@ -14,21 +14,14 @@ New versions of Shoelace are released as-needed and generally occur when a criti
## Next
- Fixed a bug in `<sl-switch>` that resulted in improper spacing between the label and the required asterisk [#1540]
- Updated `@ctrl/tinycolor` to 4.0.1 [#1542]
## 2.8.0
- Added `--isolatedModules` and `--verbatimModuleSyntax` to `tsconfig.json`. For anyone directly importing event types, they no longer provide a default export due to these options being enabled. For people using the `events/event.js` file directly, there is no change.
- Added support for submenus in `<sl-menu-item>` [#1410]
- Added the `--submenu-offset` custom property to `<sl-menu-item>` [#1410]
- Fixed an issue with focus trapping elements like `<sl-dialog>` when wrapped by other elements not checking the assigned elements of `<slot>`s. [#1537]
- Fixed type issues with the `ref` attribute in React Wrappers. [#1526]
- Fixed a regression that caused `<sl-radio-button>` to render incorrectly with gaps [#1523]
- Improved expand/collapse behavior of `<sl-tree>` to work more like users expect [#1521]
- Improved `<sl-menu-item>` so labels truncate properly instead of getting chopped and overflowing
- Removed the extra `React.Component` around `@lit-labs/react` wrapper. [#1531]
- Updated `@lit-labs/react` to v2.0.1. [#1531]
- Upgrade `@lit-labs/react` to v2.0.1. [#1531]
## 2.7.0

20
package-lock.json generated
View File

@@ -1,15 +1,15 @@
{
"name": "@shoelace-style/shoelace",
"version": "2.8.0",
"version": "2.7.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@shoelace-style/shoelace",
"version": "2.8.0",
"version": "2.7.0",
"license": "MIT",
"dependencies": {
"@ctrl/tinycolor": "^4.0.1",
"@ctrl/tinycolor": "^3.5.0",
"@floating-ui/dom": "^1.2.1",
"@lit-labs/react": "^2.0.1",
"@shoelace-style/animations": "^1.1.0",
@@ -833,11 +833,11 @@
}
},
"node_modules/@ctrl/tinycolor": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/@ctrl/tinycolor/-/tinycolor-4.0.1.tgz",
"integrity": "sha512-dfimuE1mfaqL8P8jyQzdk9yFeFUWCyhjK5VyydXgDtQO0fezr6aWaGauHnlI07BZBIF45gahb0oxJjkUcylDwQ==",
"version": "3.5.0",
"resolved": "https://registry.npmjs.org/@ctrl/tinycolor/-/tinycolor-3.5.0.tgz",
"integrity": "sha512-tlJpwF40DEQcfR/QF+wNMVyGMaO9FQp6Z1Wahj4Gk3CJQYHwA2xVG7iKDFdW6zuxZY9XWOpGcfNCTsX4McOsOg==",
"engines": {
"node": ">=14"
"node": ">=10"
}
},
"node_modules/@custom-elements-manifest/analyzer": {
@@ -17913,9 +17913,9 @@
"dev": true
},
"@ctrl/tinycolor": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/@ctrl/tinycolor/-/tinycolor-4.0.1.tgz",
"integrity": "sha512-dfimuE1mfaqL8P8jyQzdk9yFeFUWCyhjK5VyydXgDtQO0fezr6aWaGauHnlI07BZBIF45gahb0oxJjkUcylDwQ=="
"version": "3.5.0",
"resolved": "https://registry.npmjs.org/@ctrl/tinycolor/-/tinycolor-3.5.0.tgz",
"integrity": "sha512-tlJpwF40DEQcfR/QF+wNMVyGMaO9FQp6Z1Wahj4Gk3CJQYHwA2xVG7iKDFdW6zuxZY9XWOpGcfNCTsX4McOsOg=="
},
"@custom-elements-manifest/analyzer": {
"version": "0.8.3",

View File

@@ -1,7 +1,7 @@
{
"name": "@shoelace-style/shoelace",
"description": "A forward-thinking library of web components.",
"version": "2.8.0",
"version": "2.7.0",
"homepage": "https://github.com/shoelace-style/shoelace",
"author": "Cory LaViska",
"license": "MIT",
@@ -60,7 +60,7 @@
"node": ">=14.17.0"
},
"dependencies": {
"@ctrl/tinycolor": "^4.0.1",
"@ctrl/tinycolor": "^3.5.0",
"@floating-ui/dom": "^1.2.1",
"@lit-labs/react": "^2.0.1",
"@shoelace-style/animations": "^1.1.0",

View File

@@ -53,10 +53,6 @@ async function buildTheDocs(watch = false) {
output.push(data.toString());
});
child.stderr.on('data', data => {
output.push(data.toString());
});
if (watch) {
// The process doesn't terminate in watch mode so, before resolving, we listen for a known signal in stdout that
// tells us when the first build completes.

View File

@@ -5,7 +5,7 @@ meta:
layout: component
---
```html:preview
```html preview
<{{ tag }}></{{ tag }}>
```

View File

@@ -1,204 +0,0 @@
import { classMap } from 'lit/directives/class-map.js';
import { generateCalendarGrid, getAllDayNames, getMonthName, isSameDay } from '../../internal/calendar.js';
import { HasSlotController } from '../../internal/slot.js';
import { html } from 'lit';
import { LocalizeController } from '../../utilities/localize.js';
import { partMap } from '../../internal/part-map.js';
import { property } from 'lit/decorators.js';
import { watch } from '../../internal/watch.js';
import ShoelaceElement from '../../internal/shoelace-element.js';
import styles from './calendar.styles';
import type { CSSResultGroup, TemplateResult } from 'lit';
export interface RenderDayOptions {
disabled?: boolean;
content: string | TemplateResult;
}
/**
* @summary A calendar prototype for Shoelace.
* @documentation https://shoelace.style/components/calendar
*
* @since 2.0
* @status experimental
*
* @dependency sl-example
*
* @event sl-change - Emitted when the date changes.
*
* @slot footer - Optional content to place in the calendar's footer.
*
* @csspart day - Targets day cells.
* @csspart day-label - Targets the day labels (the name of the days in the grid).
* @csspart day-weekend - Targets days that fall on weekends.
* @csspart day-weekday - Targets weekdays.
* @csspart day-current-month - Targets days in the current month.
* @csspart day-previous-month - Targets days in the previous month.
* @csspart day-next-month - Targets days in the next month.
* @csspart day-today - Targets today.
* @csspart day-selected - Targets selected days.
* @csspart day-selection-start - Targets days that begin a selection.
* @csspart day-selection-end - Targets days that end a selection.
*
* @cssproperty --border-color - The calendar's border color.
* @cssproperty --border-width - The calendar's border width.
* @cssproperty --border-radius - The border radius of the calendar.
*/
export default class SlCalendar extends ShoelaceElement {
static styles: CSSResultGroup = styles;
private readonly localize = new LocalizeController(this);
private readonly hasSlotController = new HasSlotController(this, 'prefix', 'suffix');
/** The month to render, 1-12/ */
@property({ type: Number, reflect: true }) month: number = new Date().getMonth() + 1;
/** The year to render. */
@property({ type: Number, reflect: true }) year: number = new Date().getFullYear();
/** Determines how day labels are shown, e.g. "M", "Mon", or "Monday". */
@property({ attribute: 'day-labels' }) dayLabels: 'narrow' | 'short' | 'long' = 'short';
/** Determines how month labels are shown, e.g. "J", "Jan", or "January". */
@property({ attribute: 'month-labels' }) monthLabels: 'numeric' | '2-digit' | 'long' | 'short' | 'narrow' = 'long';
/** When true, dates from the previous and next month will also be shown to fill out the grid. */
@property({ attribute: 'show-adjacent-dates', type: Boolean }) showAdjacentDates = false;
/** Draws the target dates as a selection in the calendar. */
@property({ type: Array }) selectedDates: Date[] = [];
/** Moves the calendar to the current month and year. */
goToToday() {
this.month = new Date().getMonth() + 1;
this.year = new Date().getFullYear();
}
/** Moves the calendar to the previous month. */
goToPreviousMonth() {
if (this.month === 1) {
this.month = 12;
this.year--;
} else {
this.month--;
}
}
/** Moves the calendar to the next month. */
goToNextMonth() {
if (this.month === 12) {
this.month = 1;
this.year++;
} else {
this.month++;
}
}
@watch('month')
@watch('year')
handleMonthChange() {
this.emit('sl-change');
}
render() {
if (this.month < 1 || this.month > 12) {
throw new Error(`The value "${this.month}" is not a valid month.`);
}
const lang = this.lang || document.documentElement.lang;
const month = new Date(this.year, this.month - 1, 1);
const dayGrid = generateCalendarGrid(this.year, this.month);
const dayNames = getAllDayNames(lang, this.dayLabels);
//
// TODO - December is not showing a label because the month is calculated as Sat Jan 01 2022 00:00:00 GMT-0500
//
return html`
<div
class=${classMap({
calendar: true,
'calendar--has-footer': this.hasSlotController.test('footer'),
'calendar--show-adjacent-dates': this.showAdjacentDates
})}
>
<header class="calendar__header">
<sl-icon-button
name="chevron-left"
label=${this.localize.term('previousMonth')}
@click=${this.goToPreviousMonth}
></sl-icon-button>
<span class="calendar__label">
<span class="calendar__month-label">${getMonthName(month, lang, this.monthLabels)}</span>
<span class="calendar__year-label">${month.getFullYear()}</span>
</span>
<sl-icon-button
name="chevron-right"
label=${this.localize.term('nextMonth')}
@click=${this.goToNextMonth}
></sl-icon-button>
</header>
<div class="calendar__days">
${[0, 1, 2, 3, 4, 5, 6].map(day => {
return html`
<span
part=${partMap({
day: true,
'day-label': true,
'day-weekday': day > 0 && day < 6,
'day-weekend': day === 0 || day === 6
})}
class="calendar__day"
>
${dayNames[day]}
</span>
`;
})}
${dayGrid.map((day, index) => {
if (day.isCurrentMonth || this.showAdjacentDates) {
const isSelected = Array.isArray(this.selectedDates)
? this.selectedDates.some(d => isSameDay(d, day.date))
: false;
const previousDay = index > 0 ? dayGrid[index - 1] : null;
const nextDay = index < dayGrid.length - 1 ? dayGrid[index + 1] : null;
const isSelectionStart =
isSelected && previousDay ? !this.selectedDates.some(d => isSameDay(d, previousDay.date)) : false;
const isSelectionEnd =
isSelected && nextDay ? !this.selectedDates.some(d => isSameDay(d, nextDay.date)) : false;
return html`
<button
type="button"
part=${partMap({
day: true,
'day-current-month': day.isCurrentMonth,
'day-previous-month': day.isPreviousMonth,
'day-next-month': day.isNextMonth,
'day-today': day.isToday,
'day-weekday': day.isWeekday,
'day-weekend': day.isWeekend,
'day-selected': isSelected,
'day-selection-start': isSelectionStart,
'day-selection-end': isSelectionEnd
})}
class="calendar__day"
>
${day.date.getDate()}
</button>
`;
}
return html` <div class="calendar__day calendar__day--empty"></div> `;
})}
</div>
<footer class="calendar__footer">
<slot name="footer"></slot>
</footer>
</div>
`;
}
}

View File

@@ -1,119 +0,0 @@
import { css } from 'lit';
import componentStyles from '../../styles/component.styles';
export default css`
${componentStyles}
:host {
--border-color: var(--sl-color-neutral-200);
--border-radius: var(--sl-border-radius-medium);
--border-width: 0;
display: block;
}
.calendar__header {
display: flex;
align-items: center;
margin-bottom: var(--sl-spacing-x-small);
}
.calendar__header sl-icon-button {
flex: 0 0 auto;
}
.calendar__label {
flex: 1 1 auto;
text-align: center;
}
.calendar__days {
isolation: isolate;
display: grid;
grid-template-columns: repeat(7, 1fr);
}
.calendar__day {
position: relative;
display: flex;
align-items: center;
justify-content: center;
text-align: center;
border: solid var(--border-width) var(--border-color);
border-bottom: none;
background: none;
background-color: var(--sl-color-neutral-0);
font: inherit;
color: var(--sl-color-neutral-900);
min-height: 3rem;
padding: 0;
margin: 0;
}
.calendar__day:nth-child(1) {
border-top-left-radius: var(--border-radius);
}
.calendar__day:nth-child(7) {
border-top-right-radius: var(--border-radius);
}
.calendar__day:nth-last-child(1) {
border-bottom-right-radius: var(--border-radius);
}
.calendar__day:nth-last-child(7) {
border-bottom-left-radius: var(--border-radius);
}
.calendar__day:not(:nth-child(7n)) {
border-right: none;
}
.calendar__day:nth-last-child(1),
.calendar__day:nth-last-child(2),
.calendar__day:nth-last-child(3),
.calendar__day:nth-last-child(4),
.calendar__day:nth-last-child(5),
.calendar__day:nth-last-child(6),
.calendar__day:nth-last-child(7) {
border-bottom: solid var(--border-width) var(--border-color);
}
.calendar__day:focus-visible {
outline: solid 2px var(--sl-color-primary-600);
z-index: 1;
}
.calendar__day[part~='day-weekend'] {
color: var(--sl-color-rose-600);
}
.calendar__day[part~='day-today'] {
font-weight: var(--sl-font-weight-bold);
}
.calendar__day[part~='day-selected'] {
background-color: var(--sl-color-primary-100);
}
.calendar__day[part~='day-selection-start'] {
border-top-left-radius: var(--sl-border-radius-pill);
border-bottom-left-radius: var(--sl-border-radius-pill);
}
.calendar__day[part~='day-selection-end'] {
border-top-right-radius: var(--sl-border-radius-pill);
border-bottom-right-radius: var(--sl-border-radius-pill);
}
.calendar__day .calendar__day[part~='day-previous-month'],
.calendar__day[part~='day-next-month'] {
color: var(--sl-color-neutral-400);
}
.calendar__day[part~='day-previous-month'][part~='day-weekend'],
.calendar__day[part~='day-next-month'][part~='day-weekend'] {
color: var(--sl-color-rose-400);
}
`;

View File

@@ -1,9 +0,0 @@
import { expect } from '@open-wc/testing';
describe('<sl-calendar>', () => {
it('should render a component', async () => {
// const el = await fixture(html` <sl-calendar></sl-calendar> `);
const a = true;
expect(a).to.be.true;
});
});

View File

@@ -1,12 +0,0 @@
import SlCalendar from './calendar.component.js';
export * from './calendar.component.js';
export default SlCalendar;
SlCalendar.define('sl-calendar');
declare global {
interface HTMLElementTagNameMap {
'sl-calendar': SlCalendar;
}
}

View File

@@ -20,8 +20,8 @@ import SlVisuallyHidden from '../visually-hidden/visually-hidden.component.js';
import styles from './color-picker.styles.js';
import type { CSSResultGroup } from 'lit';
import type { ShoelaceFormControl } from '../../internal/shoelace-element.js';
import type { SlChangeEvent } from '../../events/sl-change.js';
import type { SlInputEvent } from '../../events/sl-input.js';
import type SlChangeEvent from '../../events/sl-change.js';
import type SlInputEvent from '../../events/sl-input.js';
const hasEyeDropper = 'EyeDropper' in window;

View File

@@ -2,9 +2,9 @@ import '../../../dist/shoelace.js';
// cspell:dictionaries lorem-ipsum
import { expect, fixture, html, waitUntil } from '@open-wc/testing';
import sinon from 'sinon';
import type { SlHideEvent } from '../../events/sl-hide';
import type { SlShowEvent } from '../../events/sl-show';
import type SlDetails from './details';
import type SlHideEvent from '../../events/sl-hide';
import type SlShowEvent from '../../events/sl-show';
describe('<sl-details>', () => {
describe('accessibility', () => {

View File

@@ -11,10 +11,10 @@ import ShoelaceElement from '../../internal/shoelace-element.js';
import SlPopup from '../popup/popup.component.js';
import styles from './dropdown.styles.js';
import type { CSSResultGroup } from 'lit';
import type { SlSelectEvent } from '../../events/sl-select.js';
import type SlButton from '../button/button.js';
import type SlIconButton from '../icon-button/icon-button.js';
import type SlMenu from '../menu/menu.js';
import type SlSelectEvent from '../../events/sl-select.js';
/**
* @summary Dropdowns expose additional content that "drops down" in a panel.

View File

@@ -1,8 +1,8 @@
import { aTimeout, elementUpdated, expect, fixture, html, oneEvent } from '@open-wc/testing';
import { registerIconLibrary } from '../../../dist/shoelace.js';
import type { SlErrorEvent } from '../../events/sl-error';
import type { SlLoadEvent } from '../../events/sl-load';
import type SlErrorEvent from '../../events/sl-error';
import type SlIcon from './icon';
import type SlLoadEvent from '../../events/sl-load';
const testLibraryIcons = {
'test-icon1': `

View File

@@ -2,8 +2,8 @@ import '../../../dist/shoelace.js';
import { expect, fixture, html, waitUntil } from '@open-wc/testing';
import { sendKeys } from '@web/test-runner-commands';
import sinon from 'sinon';
import type { SlSelectEvent } from '../../events/sl-select';
import type SlMenuItem from './menu-item';
import type SlSelectEvent from '../../events/sl-select';
describe('<sl-menu-item>', () => {
it('should pass accessibility tests', async () => {

View File

@@ -4,8 +4,8 @@ import { expect, fixture } from '@open-wc/testing';
import { html } from 'lit';
import { sendKeys } from '@web/test-runner-commands';
import sinon from 'sinon';
import type { SlSelectEvent } from '../../events/sl-select';
import type SlMenu from './menu';
import type SlSelectEvent from '../../events/sl-select';
describe('<sl-menu>', () => {
it('emits sl-select with the correct event detail when clicking an item', async () => {

View File

@@ -4,7 +4,7 @@ import { clickOnElement } from '../../internal/test.js';
import { runFormControlBaseTests } from '../../internal/test/form-control-base-tests.js';
import { sendKeys } from '@web/test-runner-commands';
import sinon from 'sinon';
import type { SlChangeEvent } from '../../events/sl-change.js';
import type SlChangeEvent from '../../events/sl-change.js';
import type SlRadio from '../radio/radio.js';
import type SlRadioGroup from './radio-group.js';

View File

@@ -18,8 +18,8 @@ import SlTag from '../tag/tag.component.js';
import styles from './select.styles.js';
import type { CSSResultGroup, TemplateResult } from 'lit';
import type { ShoelaceFormControl } from '../../internal/shoelace-element.js';
import type { SlRemoveEvent } from '../../events/sl-remove.js';
import type SlOption from '../option/option.component.js';
import type SlRemoveEvent from '../../events/sl-remove.js';
/**
* @summary Selects allow you to choose items from a menu of predefined options.

View File

@@ -215,9 +215,7 @@ export default class SlSwitch extends ShoelaceElement implements ShoelaceFormCon
<span part="thumb" class="switch__thumb"></span>
</span>
<div part="label" class="switch__label">
<slot></slot>
</div>
<slot part="label" class="switch__label"></slot>
</label>
`;
}

View File

@@ -7,10 +7,10 @@ import { queryByTestId } from '../../internal/test/data-testid-helpers.js';
import { sendKeys } from '@web/test-runner-commands';
import { waitForScrollingToEnd } from '../../internal/test/wait-for-scrolling.js';
import type { HTMLTemplateResult } from 'lit';
import type { SlTabShowEvent } from '../../events/sl-tab-show.js';
import type SlTab from '../tab/tab.js';
import type SlTabGroup from './tab-group.js';
import type SlTabPanel from '../tab-panel/tab-panel.js';
import type SlTabShowEvent from '../../events/sl-tab-show.js';
interface ClientRectangles {
body?: DOMRect;

View File

@@ -1,35 +1,35 @@
export type { SlAfterCollapseEvent } from './sl-after-collapse';
export type { SlAfterExpandEvent } from './sl-after-expand';
export type { SlAfterHideEvent } from './sl-after-hide';
export type { SlAfterShowEvent } from './sl-after-show';
export type { SlBlurEvent } from './sl-blur';
export type { SlCancelEvent } from './sl-cancel';
export type { SlChangeEvent } from './sl-change';
export type { SlClearEvent } from './sl-clear';
export type { SlCloseEvent } from './sl-close';
export type { SlCollapseEvent } from './sl-collapse';
export type { SlCopyEvent } from './sl-copy';
export type { SlErrorEvent } from './sl-error';
export type { SlExpandEvent } from './sl-expand';
export type { SlFinishEvent } from './sl-finish';
export type { SlFocusEvent } from './sl-focus';
export type { SlHideEvent } from './sl-hide';
export type { SlHoverEvent } from './sl-hover';
export type { SlInitialFocusEvent } from './sl-initial-focus';
export type { SlInputEvent } from './sl-input';
export type { SlInvalidEvent } from './sl-invalid';
export type { SlLazyChangeEvent } from './sl-lazy-change';
export type { SlLazyLoadEvent } from './sl-lazy-load';
export type { SlLoadEvent } from './sl-load';
export type { SlMutationEvent } from './sl-mutation';
export type { SlRemoveEvent } from './sl-remove';
export type { SlRepositionEvent } from './sl-reposition';
export type { SlRequestCloseEvent } from './sl-request-close';
export type { SlResizeEvent } from './sl-resize';
export type { SlSelectEvent } from './sl-select';
export type { SlSelectionChangeEvent } from './sl-selection-change';
export type { SlShowEvent } from './sl-show';
export type { SlSlideChangeEvent } from './sl-slide-change';
export type { SlStartEvent } from './sl-start';
export type { SlTabHideEvent } from './sl-tab-hide';
export type { SlTabShowEvent } from './sl-tab-show';
export type { default as SlAfterCollapseEvent } from './sl-after-collapse';
export type { default as SlAfterExpandEvent } from './sl-after-expand';
export type { default as SlAfterHideEvent } from './sl-after-hide';
export type { default as SlAfterShowEvent } from './sl-after-show';
export type { default as SlBlurEvent } from './sl-blur';
export type { default as SlCancelEvent } from './sl-cancel';
export type { default as SlChangeEvent } from './sl-change';
export type { default as SlClearEvent } from './sl-clear';
export type { default as SlCloseEvent } from './sl-close';
export type { default as SlCollapseEvent } from './sl-collapse';
export type { default as SlCopyEvent } from './sl-copy';
export type { default as SlErrorEvent } from './sl-error';
export type { default as SlExpandEvent } from './sl-expand';
export type { default as SlFinishEvent } from './sl-finish';
export type { default as SlFocusEvent } from './sl-focus';
export type { default as SlHideEvent } from './sl-hide';
export type { default as SlHoverEvent } from './sl-hover';
export type { default as SlInitialFocusEvent } from './sl-initial-focus';
export type { default as SlInputEvent } from './sl-input';
export type { default as SlInvalidEvent } from './sl-invalid';
export type { default as SlLazyChangeEvent } from './sl-lazy-change';
export type { default as SlLazyLoadEvent } from './sl-lazy-load';
export type { default as SlLoadEvent } from './sl-load';
export type { default as SlMutationEvent } from './sl-mutation';
export type { default as SlRemoveEvent } from './sl-remove';
export type { default as SlRepositionEvent } from './sl-reposition';
export type { default as SlRequestCloseEvent } from './sl-request-close';
export type { default as SlResizeEvent } from './sl-resize';
export type { default as SlSelectEvent } from './sl-select';
export type { default as SlSelectionChangeEvent } from './sl-selection-change';
export type { default as SlShowEvent } from './sl-show';
export type { default as SlSlideChangeEvent } from './sl-slide-change';
export type { default as SlStartEvent } from './sl-start';
export type { default as SlTabHideEvent } from './sl-tab-hide';
export type { default as SlTabShowEvent } from './sl-tab-show';

View File

@@ -1,7 +1,9 @@
export type SlAfterCollapseEvent = CustomEvent<Record<PropertyKey, never>>;
type SlAfterCollapseEvent = CustomEvent<Record<PropertyKey, never>>;
declare global {
interface GlobalEventHandlersEventMap {
'sl-after-collapse': SlAfterCollapseEvent;
}
}
export default SlAfterCollapseEvent;

View File

@@ -1,7 +1,9 @@
export type SlAfterExpandEvent = CustomEvent<Record<PropertyKey, never>>;
type SlAfterExpandEvent = CustomEvent<Record<PropertyKey, never>>;
declare global {
interface GlobalEventHandlersEventMap {
'sl-after-expand': SlAfterExpandEvent;
}
}
export default SlAfterExpandEvent;

View File

@@ -1,7 +1,9 @@
export type SlAfterHideEvent = CustomEvent<Record<PropertyKey, never>>;
type SlAfterHideEvent = CustomEvent<Record<PropertyKey, never>>;
declare global {
interface GlobalEventHandlersEventMap {
'sl-after-hide': SlAfterHideEvent;
}
}
export default SlAfterHideEvent;

View File

@@ -1,7 +1,9 @@
export type SlAfterShowEvent = CustomEvent<Record<PropertyKey, never>>;
type SlAfterShowEvent = CustomEvent<Record<PropertyKey, never>>;
declare global {
interface GlobalEventHandlersEventMap {
'sl-after-show': SlAfterShowEvent;
}
}
export default SlAfterShowEvent;

View File

@@ -1,7 +1,9 @@
export type SlBlurEvent = CustomEvent<Record<PropertyKey, never>>;
type SlBlurEvent = CustomEvent<Record<PropertyKey, never>>;
declare global {
interface GlobalEventHandlersEventMap {
'sl-blur': SlBlurEvent;
}
}
export default SlBlurEvent;

View File

@@ -1,7 +1,9 @@
export type SlCancelEvent = CustomEvent<Record<PropertyKey, never>>;
type SlCancelEvent = CustomEvent<Record<PropertyKey, never>>;
declare global {
interface GlobalEventHandlersEventMap {
'sl-cancel': SlCancelEvent;
}
}
export default SlCancelEvent;

View File

@@ -1,7 +1,9 @@
export type SlChangeEvent = CustomEvent<Record<PropertyKey, never>>;
type SlChangeEvent = CustomEvent<Record<PropertyKey, never>>;
declare global {
interface GlobalEventHandlersEventMap {
'sl-change': SlChangeEvent;
}
}
export default SlChangeEvent;

View File

@@ -1,7 +1,9 @@
export type SlClearEvent = CustomEvent<Record<PropertyKey, never>>;
type SlClearEvent = CustomEvent<Record<PropertyKey, never>>;
declare global {
interface GlobalEventHandlersEventMap {
'sl-clear': SlClearEvent;
}
}
export default SlClearEvent;

View File

@@ -1,7 +1,9 @@
export type SlCloseEvent = CustomEvent<Record<PropertyKey, never>>;
type SlCloseEvent = CustomEvent<Record<PropertyKey, never>>;
declare global {
interface GlobalEventHandlersEventMap {
'sl-close': SlCloseEvent;
}
}
export default SlCloseEvent;

View File

@@ -1,7 +1,9 @@
export type SlCollapseEvent = CustomEvent<Record<PropertyKey, never>>;
type SlCollapseEvent = CustomEvent<Record<PropertyKey, never>>;
declare global {
interface GlobalEventHandlersEventMap {
'sl-collapse': SlCollapseEvent;
}
}
export default SlCollapseEvent;

View File

@@ -1,7 +1,9 @@
export type SlCopyEvent = CustomEvent<{ value: string }>;
type SlCopyEvent = CustomEvent<{ value: string }>;
declare global {
interface GlobalEventHandlersEventMap {
'sl-copy': SlCopyEvent;
}
}
export default SlCopyEvent;

View File

@@ -1,7 +1,9 @@
export type SlErrorEvent = CustomEvent<{ status?: number }>;
type SlErrorEvent = CustomEvent<{ status?: number }>;
declare global {
interface GlobalEventHandlersEventMap {
'sl-error': SlErrorEvent;
}
}
export default SlErrorEvent;

View File

@@ -1,7 +1,9 @@
export type SlExpandEvent = CustomEvent<Record<PropertyKey, never>>;
type SlExpandEvent = CustomEvent<Record<PropertyKey, never>>;
declare global {
interface GlobalEventHandlersEventMap {
'sl-expand': SlExpandEvent;
}
}
export default SlExpandEvent;

View File

@@ -1,7 +1,9 @@
export type SlFinishEvent = CustomEvent<Record<PropertyKey, never>>;
type SlFinishEvent = CustomEvent<Record<PropertyKey, never>>;
declare global {
interface GlobalEventHandlersEventMap {
'sl-finish': SlFinishEvent;
}
}
export default SlFinishEvent;

View File

@@ -1,7 +1,9 @@
export type SlFocusEvent = CustomEvent<Record<PropertyKey, never>>;
type SlFocusEvent = CustomEvent<Record<PropertyKey, never>>;
declare global {
interface GlobalEventHandlersEventMap {
'sl-focus': SlFocusEvent;
}
}
export default SlFocusEvent;

View File

@@ -1,7 +1,9 @@
export type SlHideEvent = CustomEvent<Record<PropertyKey, never>>;
type SlHideEvent = CustomEvent<Record<PropertyKey, never>>;
declare global {
interface GlobalEventHandlersEventMap {
'sl-hide': SlHideEvent;
}
}
export default SlHideEvent;

View File

@@ -1,4 +1,4 @@
export type SlHoverEvent = CustomEvent<{
type SlHoverEvent = CustomEvent<{
phase: 'start' | 'move' | 'end';
value: number;
}>;
@@ -8,3 +8,5 @@ declare global {
'sl-hover': SlHoverEvent;
}
}
export default SlHoverEvent;

View File

@@ -1,7 +1,9 @@
export type SlInitialFocusEvent = CustomEvent<Record<PropertyKey, never>>;
type SlInitialFocusEvent = CustomEvent<Record<PropertyKey, never>>;
declare global {
interface GlobalEventHandlersEventMap {
'sl-initial-focus': SlInitialFocusEvent;
}
}
export default SlInitialFocusEvent;

View File

@@ -1,7 +1,9 @@
export type SlInputEvent = CustomEvent<Record<PropertyKey, never>>;
type SlInputEvent = CustomEvent<Record<PropertyKey, never>>;
declare global {
interface GlobalEventHandlersEventMap {
'sl-input': SlInputEvent;
}
}
export default SlInputEvent;

View File

@@ -1,7 +1,9 @@
export type SlInvalidEvent = CustomEvent<Record<PropertyKey, never>>;
type SlInvalidEvent = CustomEvent<Record<PropertyKey, never>>;
declare global {
interface GlobalEventHandlersEventMap {
'sl-invalid': SlInvalidEvent;
}
}
export default SlInvalidEvent;

View File

@@ -1,7 +1,9 @@
export type SlLazyChangeEvent = CustomEvent<Record<PropertyKey, never>>;
type SlLazyChangeEvent = CustomEvent<Record<PropertyKey, never>>;
declare global {
interface GlobalEventHandlersEventMap {
'sl-lazy-change': SlLazyChangeEvent;
}
}
export default SlLazyChangeEvent;

View File

@@ -1,7 +1,9 @@
export type SlLazyLoadEvent = CustomEvent<Record<PropertyKey, never>>;
type SlLazyLoadEvent = CustomEvent<Record<PropertyKey, never>>;
declare global {
interface GlobalEventHandlersEventMap {
'sl-lazy-load': SlLazyLoadEvent;
}
}
export default SlLazyLoadEvent;

View File

@@ -1,7 +1,9 @@
export type SlLoadEvent = CustomEvent<Record<PropertyKey, never>>;
type SlLoadEvent = CustomEvent<Record<PropertyKey, never>>;
declare global {
interface GlobalEventHandlersEventMap {
'sl-load': SlLoadEvent;
}
}
export default SlLoadEvent;

View File

@@ -1,7 +1,9 @@
export type SlMutationEvent = CustomEvent<{ mutationList: MutationRecord[] }>;
type SlMutationEvent = CustomEvent<{ mutationList: MutationRecord[] }>;
declare global {
interface GlobalEventHandlersEventMap {
'sl-mutation': SlMutationEvent;
}
}
export default SlMutationEvent;

View File

@@ -1,7 +1,9 @@
export type SlRemoveEvent = CustomEvent<Record<PropertyKey, never>>;
type SlRemoveEvent = CustomEvent<Record<PropertyKey, never>>;
declare global {
interface GlobalEventHandlersEventMap {
'sl-remove': SlRemoveEvent;
}
}
export default SlRemoveEvent;

View File

@@ -1,7 +1,9 @@
export type SlRepositionEvent = CustomEvent<Record<PropertyKey, never>>;
type SlRepositionEvent = CustomEvent<Record<PropertyKey, never>>;
declare global {
interface GlobalEventHandlersEventMap {
'sl-reposition': SlRepositionEvent;
}
}
export default SlRepositionEvent;

View File

@@ -1,7 +1,9 @@
export type SlRequestCloseEvent = CustomEvent<{ source: 'close-button' | 'keyboard' | 'overlay' }>;
type SlRequestCloseEvent = CustomEvent<{ source: 'close-button' | 'keyboard' | 'overlay' }>;
declare global {
interface GlobalEventHandlersEventMap {
'sl-request-close': SlRequestCloseEvent;
}
}
export default SlRequestCloseEvent;

View File

@@ -1,7 +1,9 @@
export type SlResizeEvent = CustomEvent<{ entries: ResizeObserverEntry[] }>;
type SlResizeEvent = CustomEvent<{ entries: ResizeObserverEntry[] }>;
declare global {
interface GlobalEventHandlersEventMap {
'sl-resize': SlResizeEvent;
}
}
export default SlResizeEvent;

View File

@@ -1,9 +1,11 @@
import type SlMenuItem from '../components/menu-item/menu-item';
export type SlSelectEvent = CustomEvent<{ item: SlMenuItem }>;
type SlSelectEvent = CustomEvent<{ item: SlMenuItem }>;
declare global {
interface GlobalEventHandlersEventMap {
'sl-select': SlSelectEvent;
}
}
export default SlSelectEvent;

View File

@@ -1,9 +1,11 @@
import type SlTreeItem from '../components/tree-item/tree-item';
export type SlSelectionChangeEvent = CustomEvent<{ selection: SlTreeItem[] }>;
type SlSelectionChangeEvent = CustomEvent<{ selection: SlTreeItem[] }>;
declare global {
interface GlobalEventHandlersEventMap {
'sl-selection-change': SlSelectionChangeEvent;
}
}
export default SlSelectionChangeEvent;

View File

@@ -1,7 +1,9 @@
export type SlShowEvent = CustomEvent<Record<PropertyKey, never>>;
type SlShowEvent = CustomEvent<Record<PropertyKey, never>>;
declare global {
interface GlobalEventHandlersEventMap {
'sl-show': SlShowEvent;
}
}
export default SlShowEvent;

View File

@@ -1,9 +1,11 @@
import type SlCarouselItem from '../components/carousel-item/carousel-item';
export type SlSlideChangeEvent = CustomEvent<{ index: number; slide: SlCarouselItem }>;
type SlSlideChangeEvent = CustomEvent<{ index: number; slide: SlCarouselItem }>;
declare global {
interface GlobalEventHandlersEventMap {
'sl-slide-change': SlSlideChangeEvent;
}
}
export default SlSlideChangeEvent;

View File

@@ -1,7 +1,9 @@
export type SlStartEvent = CustomEvent<Record<PropertyKey, never>>;
type SlStartEvent = CustomEvent<Record<PropertyKey, never>>;
declare global {
interface GlobalEventHandlersEventMap {
'sl-start': SlStartEvent;
}
}
export default SlStartEvent;

View File

@@ -1,7 +1,9 @@
export type SlTabHideEvent = CustomEvent<{ name: string }>;
type SlTabHideEvent = CustomEvent<{ name: string }>;
declare global {
interface GlobalEventHandlersEventMap {
'sl-tab-hide': SlTabHideEvent;
}
}
export default SlTabHideEvent;

View File

@@ -1,7 +1,9 @@
export type SlTabShowEvent = CustomEvent<{ name: string }>;
type SlTabShowEvent = CustomEvent<{ name: string }>;
declare global {
interface GlobalEventHandlersEventMap {
'sl-tab-show': SlTabShowEvent;
}
}
export default SlTabShowEvent;

View File

@@ -1,22 +0,0 @@
/**
* Use a generator so we can iterate and possibly break early.
* @example
* // to operate like a regular array. This kinda nullifies generator benefits, but worth knowing if you need the whole array.
* const allActiveElements = [...activeElements()]
*
* // Early return
* for (const activeElement of activeElements()) {
* if (<cond>) {
* break; // Break the loop, dont need to iterate over the whole array or store an array in memory!
* }
* }
*/
export function* activeElements(activeElement: Element | null = document.activeElement): Generator<Element> {
if (activeElement === null || activeElement === undefined) return;
yield activeElement;
if ('shadowRoot' in activeElement && activeElement.shadowRoot && activeElement.shadowRoot.mode !== 'closed') {
yield* activeElements(activeElement.shadowRoot.activeElement);
}
}

View File

@@ -1,141 +0,0 @@
export interface CalendarDay {
date: Date;
isToday: boolean;
isWeekday: boolean;
isWeekend: boolean;
isCurrentMonth: boolean;
isPreviousMonth: boolean;
isNextMonth: boolean;
}
export interface CalendarGridOptions {
weekStartsWith: 'sunday' | 'monday';
}
/** Generates a calendar grid. Month should be 1-12, not 0-11. */
export function generateCalendarGrid(year: number, month: number, options?: Partial<CalendarGridOptions>) {
const weekStartsWith = options?.weekStartsWith || 'sunday';
const today = new Date();
const dayThisMonthStartsWith = new Date(year, month - 1, 1).getDay();
const lastDayOfMonth = new Date(year, month, 0).getDate();
const lastDayOfPreviousMonth =
month === 1 ? new Date(year - 1, 1, 0).getDate() : new Date(year, month - 1, 0).getDate();
const dayGrid: CalendarDay[] = [];
let day = 1;
do {
const date = new Date(year, month - 1, day);
let dayOfWeek = new Date(year, month - 1, day).getDay();
if (weekStartsWith === 'sunday') {
//
// TODO
//
}
// Days in the previous month
if (day === 1) {
let lastMonthDay = lastDayOfPreviousMonth - dayThisMonthStartsWith + 1;
for (let i = 0; i < dayThisMonthStartsWith; i++) {
const dayOfLastMonth = new Date(year, month - 2, lastMonthDay);
dayGrid.push({
date: dayOfLastMonth,
isToday: isSameDay(dayOfLastMonth, today),
isWeekday: isWeekday(dayOfLastMonth),
isWeekend: isWeekend(dayOfLastMonth),
isCurrentMonth: false,
isPreviousMonth: true,
isNextMonth: false
});
lastMonthDay++;
}
}
dayGrid.push({
date,
isToday: isSameDay(date, today),
isWeekday: isWeekday(date),
isWeekend: isWeekend(date),
isCurrentMonth: true,
isPreviousMonth: false,
isNextMonth: false
});
// Days in the next month
if (day === lastDayOfMonth) {
let nextMonthDay = 1;
for (dayOfWeek; dayOfWeek < 6; dayOfWeek++) {
const dayOfNextMonth = new Date(year, month, nextMonthDay);
dayGrid.push({
date: dayOfNextMonth,
isToday: isSameDay(dayOfNextMonth, today),
isWeekday: isWeekday(dayOfNextMonth),
isWeekend: isWeekend(dayOfNextMonth),
isCurrentMonth: false,
isPreviousMonth: false,
isNextMonth: true
});
nextMonthDay++;
}
}
day++;
} while (day <= lastDayOfMonth);
return dayGrid;
}
/** Generates a localized array of day names. */
export function getAllDayNames(locale = 'en', format: Intl.DateTimeFormatOptions['weekday'] = 'long') {
const formatter = new Intl.DateTimeFormat(locale, { weekday: format, timeZone: 'UTC' });
const days = [1, 2, 3, 4, 5, 6, 7].map(day => {
const dd = day < 10 ? `0${day}` : day;
return new Date(`2017-01-${dd}T00:00:00+00:00`);
});
return days.map(date => formatter.format(date));
}
/** Generates a localized array of month names. */
export function getAllMonthNames(locale = 'en', format: Intl.DateTimeFormatOptions['month'] = 'long') {
const formatter = new Intl.DateTimeFormat(locale, { month: format, timeZone: 'UTC' });
const months = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12].map(month => {
const mm = month < 10 ? `0${month}` : month;
return new Date(`2017-${mm}-01T00:00:00+00:00`);
});
return months.map(date => formatter.format(date));
}
/** Determines if two dates are the same day. */
export function isSameDay(date1: Date, date2: Date) {
return (
date1.getFullYear() === date2.getFullYear() &&
date1.getMonth() === date2.getMonth() &&
date1.getDate() === date2.getDate()
);
}
/** Determines if the date is a weekend. */
export function isWeekend(date: Date) {
const day = date.getDay();
return day === 0 || day === 6;
}
/** Determines if the date is a weekday. */
export function isWeekday(date: Date) {
const day = date.getDay();
return day > 0 && day < 6;
}
/** Returns a localized, human-readable day name. */
export function getDayName(date: Date, locale = 'en', format: Intl.DateTimeFormatOptions['weekday'] = 'long') {
return getAllDayNames(locale, format)[date.getDate() - 1];
}
/** Returns a localized, human-readable month name. */
export function getMonthName(date: Date, locale = 'en', format: Intl.DateTimeFormatOptions['month'] = 'long') {
return getAllMonthNames(locale, format)[date.getMonth()];
}

View File

@@ -1,4 +1,3 @@
import { activeElements } from './active-elements.js';
import { getTabbableElements } from './tabbable.js';
let activeModals: HTMLElement[] = [];
@@ -56,20 +55,6 @@ export default class Modal {
return getTabbableElements(this.element).findIndex(el => el === this.currentFocus);
}
/**
* Checks if the `startElement` is already focused. This is important if the modal already
* has an existing focus prior to the first tab key.
*/
startElementAlreadyFocused(startElement: HTMLElement) {
for (const activeElement of activeElements()) {
if (startElement === activeElement) {
return true;
}
}
return false;
}
handleKeyDown = (event: KeyboardEvent) => {
if (event.key !== 'Tab') return;
@@ -83,10 +68,7 @@ export default class Modal {
const tabbableElements = getTabbableElements(this.element);
const start = tabbableElements[0];
// Sometimes we programmatically focus the first element in a modal.
// Lets make sure the start element isn't already focused.
let focusIndex = this.startElementAlreadyFocused(start) ? 0 : this.currentFocusIndex;
let focusIndex = this.currentFocusIndex;
if (focusIndex === -1) {
this.currentFocus = start;

View File

@@ -1,11 +0,0 @@
export function partMap(map: { [partName: string]: boolean }) {
const parts = [];
for (const [key, value] of Object.entries(map)) {
if (value) {
parts.push(key);
}
}
return parts.join(' ');
}

View File

@@ -1,147 +0,0 @@
import { elementUpdated, expect, fixture } from '@open-wc/testing';
import '../../dist/shoelace.js';
import { activeElements } from './active-elements.js';
import { html } from 'lit';
import { sendKeys } from '@web/test-runner-commands';
async function holdShiftKey(callback: () => Promise<void>) {
await sendKeys({ down: 'Shift' });
await callback();
await sendKeys({ up: 'Shift' });
}
const tabKey =
navigator.userAgent.includes('Safari') && !navigator.userAgent.includes('HeadlessChrome') ? 'Alt+Tab' : 'Tab';
// Simple helper to turn the activeElements generator into an array
function activeElementsArray() {
return [...activeElements()];
}
function getDeepestActiveElement() {
return activeElementsArray().pop();
}
window.customElements.define(
'tab-test-1',
class extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: 'open' });
}
connectedCallback() {
this.shadowRoot!.innerHTML = `
<sl-drawer>
<slot name="label" slot="label"></slot>
<slot></slot>
<slot name="footer" slot="footer"></slot>
</sl-drawer>
`;
}
}
);
it('Should allow tabbing to slotted elements', async () => {
const el = await fixture(html`
<tab-test-1>
<div slot="label">
<sl-button id="focus-1">Focus 1</sl-button>
</div>
<div>
<!-- Focus 2 lives as the close-button from <sl-drawer> -->
<sl-button id="focus-3">Focus 3</sl-button>
<button id="focus-4">Focus 4</sl-button>
<input id="focus-5" value="Focus 5">
</div>
<div slot="footer">
<div id="focus-6" tabindex="0">Focus 6</div>
<button tabindex="-1">No Focus</button>
</div>
</tab-test-1>
`);
const drawer = el.shadowRoot?.querySelector('sl-drawer');
if (drawer === null || drawer === undefined) throw Error('Could not find drawer inside of the test element');
await drawer.show();
await elementUpdated(drawer);
const focusZero = drawer.shadowRoot?.querySelector("[role='dialog']");
if (focusZero === null || focusZero === undefined) throw Error('Could not find dialog panel inside <sl-drawer>');
const focusOne = el.querySelector('#focus-1');
const focusTwo = drawer.shadowRoot?.querySelector("[part~='close-button']");
if (focusTwo === null || focusTwo === undefined) throw Error('Could not find close button inside <sl-drawer>');
const focusThree = el.querySelector('#focus-3');
const focusFour = el.querySelector('#focus-4');
const focusFive = el.querySelector('#focus-5');
const focusSix = el.querySelector('#focus-6');
// When we open drawer, we should be focused on the panel to start.
expect(getDeepestActiveElement()).to.equal(focusZero);
await sendKeys({ press: tabKey });
expect(activeElementsArray()).to.include(focusOne);
// When we hit the <Tab> key we should go to the "close button" on the drawer
await sendKeys({ press: tabKey });
expect(activeElementsArray()).to.include(focusTwo);
await sendKeys({ press: tabKey });
expect(activeElementsArray()).to.include(focusThree);
await sendKeys({ press: tabKey });
expect(activeElementsArray()).to.include(focusFour);
await sendKeys({ press: tabKey });
expect(activeElementsArray()).to.include(focusFive);
await sendKeys({ press: tabKey });
expect(activeElementsArray()).to.include(focusSix);
// Now we should loop back to #panel
await sendKeys({ press: tabKey });
expect(activeElementsArray()).to.include(focusZero);
// Now we should loop back to #panel
await sendKeys({ press: tabKey });
expect(activeElementsArray()).to.include(focusOne);
// Let's reset and try from starting point 0 and go backwards.
await holdShiftKey(async () => await sendKeys({ press: tabKey }));
expect(activeElementsArray()).to.include(focusZero);
await holdShiftKey(async () => await sendKeys({ press: tabKey }));
expect(activeElementsArray()).to.include(focusSix);
await holdShiftKey(async () => await sendKeys({ press: tabKey }));
expect(activeElementsArray()).to.include(focusFive);
await holdShiftKey(async () => await sendKeys({ press: tabKey }));
expect(activeElementsArray()).to.include(focusFour);
await holdShiftKey(async () => await sendKeys({ press: tabKey }));
expect(activeElementsArray()).to.include(focusThree);
await holdShiftKey(async () => await sendKeys({ press: tabKey }));
expect(activeElementsArray()).to.include(focusTwo);
await holdShiftKey(async () => await sendKeys({ press: tabKey }));
expect(activeElementsArray()).to.include(focusOne);
await holdShiftKey(async () => await sendKeys({ press: tabKey }));
expect(activeElementsArray()).to.include(focusZero);
await holdShiftKey(async () => await sendKeys({ press: tabKey }));
expect(activeElementsArray()).to.include(focusSix);
});

View File

@@ -69,32 +69,11 @@ export function getTabbableBoundary(root: HTMLElement | ShadowRoot) {
}
export function getTabbableElements(root: HTMLElement | ShadowRoot) {
const tabbableElements: HTMLElement[] = [];
const allElements: HTMLElement[] = [];
function walk(el: HTMLElement | ShadowRoot) {
if (el instanceof Element) {
// if the element has "inert" we can just no-op it.
if (el.hasAttribute('inert')) {
return;
}
if (!tabbableElements.includes(el) && isTabbable(el)) {
tabbableElements.push(el);
}
/**
* This looks funky. Basically a slot's children will always be picked up *if* they're within the `root` element.
* However, there is an edge case when, if the `root` is wrapped by another shadow DOM, it won't grab the children.
* This fixes that fun edge case.
*/
const slotChildrenOutsideRootElement = (slotElement: HTMLSlotElement) =>
(slotElement.getRootNode({ composed: true }) as ShadowRoot | null)?.host !== root;
if (el instanceof HTMLSlotElement && slotChildrenOutsideRootElement(el)) {
el.assignedElements({ flatten: true }).forEach((assignedEl: HTMLElement) => {
walk(assignedEl);
});
}
allElements.push(el);
if (el.shadowRoot !== null && el.shadowRoot.mode === 'open') {
walk(el.shadowRoot);
@@ -107,14 +86,10 @@ export function getTabbableElements(root: HTMLElement | ShadowRoot) {
// Collect all elements including the root
walk(root);
return tabbableElements;
// Is this worth having? Most sorts will always add increased overhead. And positive tabindexes shouldn't really be used.
// So is it worth being right? Or fast?
// return tabbableElements.filter(isTabbable).sort((a, b) => {
// // Make sure we sort by tabindex.
// const aTabindex = Number(a.getAttribute('tabindex')) || 0;
// const bTabindex = Number(b.getAttribute('tabindex')) || 0;
// return bTabindex - aTabindex;
// });
return allElements.filter(isTabbable).sort((a, b) => {
// Make sure we sort by tabindex.
const aTabindex = Number(a.getAttribute('tabindex')) || 0;
const bTabindex = Number(b.getAttribute('tabindex')) || 0;
return bTabindex - aTabindex;
});
}

View File

@@ -8,7 +8,6 @@ export { default as SlBreadcrumb } from './components/breadcrumb/breadcrumb.js';
export { default as SlBreadcrumbItem } from './components/breadcrumb-item/breadcrumb-item.js';
export { default as SlButton } from './components/button/button.js';
export { default as SlButtonGroup } from './components/button-group/button-group.js';
export { default as SlCalendar } from './components/calendar/calendar.js';
export { default as SlCard } from './components/card/card.js';
export { default as SlCarousel } from './components/carousel/carousel.js';
export { default as SlCarouselItem } from './components/carousel-item/carousel-item.js';

View File

@@ -16,14 +16,12 @@ const translation: Translation = {
goToSlide: (slide, count) => `Go to slide ${slide} of ${count}`,
hidePassword: 'Hide password',
loading: 'Loading',
nextMonth: 'Next month',
nextSlide: 'Next slide',
numOptionsSelected: num => {
if (num === 0) return 'No options selected';
if (num === 1) return '1 option selected';
return `${num} options selected`;
},
previousMonth: 'Previous month',
previousSlide: 'Previous slide',
progress: 'Progress',
remove: 'Remove',

View File

@@ -23,10 +23,8 @@ export interface Translation extends DefaultTranslation {
goToSlide: (slide: number, count: number) => string;
hidePassword: string;
loading: string;
nextMonth?: string; // TODO - add to other language packs and remove optional ? flag
nextSlide: string;
numOptionsSelected: (num: number) => string;
previousMonth?: string; // TODO - add to other language packs and remove optional ? flag
previousSlide: string;
progress: string;
remove: string;

View File

@@ -28,8 +28,6 @@
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"useUnknownInCatchVariables": true,
"isolatedModules": true,
"verbatimModuleSyntax": true,
"types": [
"mocha",
"user-agent-data-types"