add control part to select

pull/540/head
Cory LaViska 2021-09-24 08:48:01 -04:00
rodzic e1471ec9a1
commit 8c3888da02
4 zmienionych plików z 27 dodań i 24 usunięć

Wyświetl plik

@ -10,6 +10,8 @@ _During the beta period, these restrictions may be relaxed in the event of a mis
- Added initial surface design tokens - Added initial surface design tokens
- Added missing background color to `<sl-details>` - Added missing background color to `<sl-details>`
- Added the `control` part to `<sl-select>` so you can target the main control with CSS [#538](https://github.com/shoelace-style/shoelace/issues/538)
- Changed the default `distance` in `<sl-dropdown>` from `2` to `0` [#538](https://github.com/shoelace-style/shoelace/issues/538)
- Modified the color scale to no longer use a luminance shift - Modified the color scale to no longer use a luminance shift
## 2.0.0-beta.52 ## 2.0.0-beta.52
@ -19,7 +21,6 @@ _During the beta period, these restrictions may be relaxed in the event of a mis
- Added the `--speed` custom property to `<sl-spinner>` - Added the `--speed` custom property to `<sl-spinner>`
- Added the `--size` and `--track-width` custom properties to `<sl-progress-ring>` - Added the `--size` and `--track-width` custom properties to `<sl-progress-ring>`
- Added tests for `<sl-badge>` [#530](https://github.com/shoelace-style/shoelace/pull/530) - Added tests for `<sl-badge>` [#530](https://github.com/shoelace-style/shoelace/pull/530)
- Changed the default `distance` in `<sl-dropdown>` from `2` to `0`
- Fixed a bug where `<sl-tab>` wasn't using a border radius token [#523](https://github.com/shoelace-style/shoelace/issues/523) - Fixed a bug where `<sl-tab>` wasn't using a border radius token [#523](https://github.com/shoelace-style/shoelace/issues/523)
- Fixed a bug in the Remix Icons example where some icons would 404 [#528](https://github.com/shoelace-style/shoelace/issues/528) - Fixed a bug in the Remix Icons example where some icons would 404 [#528](https://github.com/shoelace-style/shoelace/issues/528)
- Updated `<sl-progress-ring>` to use only CSS for styling - Updated `<sl-progress-ring>` to use only CSS for styling

Wyświetl plik

@ -14,7 +14,7 @@ export default css`
display: block; display: block;
} }
.select__box { .select__control {
display: inline-flex; display: inline-flex;
align-items: center; align-items: center;
justify-content: start; justify-content: start;
@ -31,13 +31,13 @@ export default css`
cursor: pointer; cursor: pointer;
} }
.select:not(.select--disabled) .select__box:hover { .select:not(.select--disabled) .select__control:hover {
background-color: rgb(var(--sl-input-background-color-hover)); background-color: rgb(var(--sl-input-background-color-hover));
border-color: rgb(var(--sl-input-border-color-hover)); border-color: rgb(var(--sl-input-border-color-hover));
color: rgb(var(--sl-input-color-hover)); color: rgb(var(--sl-input-color-hover));
} }
.select.select--focused:not(.select--disabled) .select__box { .select.select--focused:not(.select--disabled) .select__control {
background-color: rgb(var(--sl-input-background-color-focus)); background-color: rgb(var(--sl-input-background-color-focus));
border-color: rgb(var(--sl-input-border-color-focus)); border-color: rgb(var(--sl-input-border-color-focus));
box-shadow: var(--sl-focus-ring); box-shadow: var(--sl-focus-ring);
@ -45,7 +45,7 @@ export default css`
color: rgb(var(--sl-input-color-focus)); color: rgb(var(--sl-input-color-focus));
} }
.select--disabled .select__box { .select--disabled .select__control {
background-color: rgb(var(--sl-input-background-color-disabled)); background-color: rgb(var(--sl-input-background-color-disabled));
border-color: rgb(var(--sl-input-border-color-disabled)); border-color: rgb(var(--sl-input-border-color-disabled));
color: rgb(var(--sl-input-color-disabled)); color: rgb(var(--sl-input-color-disabled));
@ -141,7 +141,7 @@ export default css`
*/ */
/* Small */ /* Small */
.select--small .select__box { .select--small .select__control {
border-radius: var(--sl-input-border-radius-small); border-radius: var(--sl-input-border-radius-small);
font-size: var(--sl-input-font-size-small); font-size: var(--sl-input-font-size-small);
min-height: var(--sl-input-height-small); min-height: var(--sl-input-height-small);
@ -184,7 +184,7 @@ export default css`
} }
/* Medium */ /* Medium */
.select--medium .select__box { .select--medium .select__control {
border-radius: var(--sl-input-border-radius-medium); border-radius: var(--sl-input-border-radius-medium);
font-size: var(--sl-input-font-size-medium); font-size: var(--sl-input-font-size-medium);
min-height: var(--sl-input-height-medium); min-height: var(--sl-input-height-medium);
@ -227,7 +227,7 @@ export default css`
} }
/* Large */ /* Large */
.select--large .select__box { .select--large .select__control {
border-radius: var(--sl-input-border-radius-large); border-radius: var(--sl-input-border-radius-large);
font-size: var(--sl-input-font-size-large); font-size: var(--sl-input-font-size-large);
min-height: var(--sl-input-height-large); min-height: var(--sl-input-height-large);
@ -271,15 +271,15 @@ export default css`
/* /*
* Pill modifier * Pill modifier
*/ */
.select--pill.select--small .select__box { .select--pill.select--small .select__control {
border-radius: var(--sl-input-height-small); border-radius: var(--sl-input-height-small);
} }
.select--pill.select--medium .select__box { .select--pill.select--medium .select__control {
border-radius: var(--sl-input-height-medium); border-radius: var(--sl-input-height-medium);
} }
.select--pill.select--large .select__box { .select--pill.select--large .select__control {
border-radius: var(--sl-input-height-large); border-radius: var(--sl-input-height-large);
} }
`; `;

Wyświetl plik

@ -30,12 +30,12 @@ describe('<sl-select>', () => {
<sl-menu-item value="option-3">Option 3</sl-menu-item> <sl-menu-item value="option-3">Option 3</sl-menu-item>
</sl-select> </sl-select>
`)) as SlSelect; `)) as SlSelect;
const selectBox = el.shadowRoot.querySelector('.select__box') as HTMLSelectElement; const control = el.shadowRoot.querySelector('.select__control') as HTMLSelectElement;
selectBox.focus(); control.focus();
const rKeyEvent = new KeyboardEvent('keydown', { key: 'r' }); const rKeyEvent = new KeyboardEvent('keydown', { key: 'r' });
selectBox.dispatchEvent(rKeyEvent); control.dispatchEvent(rKeyEvent);
await aTimeout(100); await aTimeout(100);
expect(selectBox.getAttribute('aria-expanded')).to.equal('true'); expect(control.getAttribute('aria-expanded')).to.equal('true');
}); });
it('should not open the menu when ctrl + R is pressed with sl-select is on focus', async () => { it('should not open the menu when ctrl + R is pressed with sl-select is on focus', async () => {
@ -46,11 +46,11 @@ describe('<sl-select>', () => {
<sl-menu-item value="option-3">Option 3</sl-menu-item> <sl-menu-item value="option-3">Option 3</sl-menu-item>
</sl-select> </sl-select>
`)) as SlSelect; `)) as SlSelect;
const selectBox = el.shadowRoot.querySelector('.select__box') as HTMLSelectElement; const control = el.shadowRoot.querySelector('.select__control') as HTMLSelectElement;
selectBox.focus(); control.focus();
const rKeyEvent = new KeyboardEvent('keydown', { key: 'r', ctrlKey: true }); const rKeyEvent = new KeyboardEvent('keydown', { key: 'r', ctrlKey: true });
selectBox.dispatchEvent(rKeyEvent); control.dispatchEvent(rKeyEvent);
await aTimeout(100); await aTimeout(100);
expect(selectBox.getAttribute('aria-expanded')).to.equal('false'); expect(control.getAttribute('aria-expanded')).to.equal('false');
}); });
}); });

Wyświetl plik

@ -44,6 +44,7 @@ let id = 0;
* *
* @csspart base - The component's base wrapper. * @csspart base - The component's base wrapper.
* @csspart clear-button - The input's clear button, exported from <sl-input>. * @csspart clear-button - The input's clear button, exported from <sl-input>.
* @csspart control - The container that holds the prefix, label, and suffix.
* @csspart form-control - The form control that wraps the label, input, and help text. * @csspart form-control - The form control that wraps the label, input, and help text.
* @csspart help-text - The select's help text. * @csspart help-text - The select's help text.
* @csspart icon - The select's icon. * @csspart icon - The select's icon.
@ -59,7 +60,7 @@ export default class SlSelect extends LitElement {
static styles = styles; static styles = styles;
@query('.select') dropdown: SlDropdown; @query('.select') dropdown: SlDropdown;
@query('.select__box') box: SlDropdown; @query('.select__control') control: SlDropdown;
@query('.select__hidden-select') input: HTMLInputElement; @query('.select__hidden-select') input: HTMLInputElement;
@query('.select__menu') menu: SlMenu; @query('.select__menu') menu: SlMenu;
@ -266,7 +267,7 @@ export default class SlSelect extends LitElement {
} }
handleLabelClick() { handleLabelClick() {
const box = this.shadowRoot?.querySelector('.select__box') as HTMLElement; const box = this.shadowRoot?.querySelector('.select__control') as HTMLElement;
box.focus(); box.focus();
} }
@ -293,7 +294,7 @@ export default class SlSelect extends LitElement {
this.isOpen = false; this.isOpen = false;
// Restore focus on the box after the menu is hidden // Restore focus on the box after the menu is hidden
this.box.focus(); this.control.focus();
} }
@watch('multiple') @watch('multiple')
@ -351,7 +352,7 @@ export default class SlSelect extends LitElement {
} }
resizeMenu() { resizeMenu() {
const box = this.shadowRoot?.querySelector('.select__box') as HTMLElement; const box = this.shadowRoot?.querySelector('.select__control') as HTMLElement;
this.menu.style.width = `${box.clientWidth}px`; this.menu.style.width = `${box.clientWidth}px`;
if (this.dropdown) { if (this.dropdown) {
@ -464,9 +465,10 @@ export default class SlSelect extends LitElement {
@sl-hide=${this.handleMenuHide} @sl-hide=${this.handleMenuHide}
> >
<div <div
part="control"
slot="trigger" slot="trigger"
id=${this.inputId} id=${this.inputId}
class="select__box" class="select__control"
role="combobox" role="combobox"
aria-labelledby=${ifDefined( aria-labelledby=${ifDefined(
getLabelledBy({ getLabelledBy({