Skip to content

Commit

Permalink
Select component: add a suffix to .form-control-input
Browse files Browse the repository at this point in the history
  • Loading branch information
Nic Newdigate committed Jun 11, 2024
1 parent 6092796 commit dbd4ba8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
27 changes: 27 additions & 0 deletions docs/pages/components/select.md
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,33 @@ Use the `prefix` slot to prepend an icon to the control.
</sl-select>
```

### Suffix Icons

Use the `suffix` slot to append an icon to the control.

```html:preview
<sl-select placeholder="Small" size="small" clearable>
<sl-icon name="house" slot="suffix"></sl-icon>
<sl-option value="option-1">Option 1</sl-option>
<sl-option value="option-2">Option 2</sl-option>
<sl-option value="option-3">Option 3</sl-option>
</sl-select>
<br />
<sl-select placeholder="Medium" size="medium" clearable>
<sl-icon name="house" slot="suffix"></sl-icon>
<sl-option value="option-1">Option 1</sl-option>
<sl-option value="option-2">Option 2</sl-option>
<sl-option value="option-3">Option 3</sl-option>
</sl-select>
<br />
<sl-select placeholder="Large" size="large" clearable>
<sl-icon name="house" slot="suffix"></sl-icon>
<sl-option value="option-1">Option 1</sl-option>
<sl-option value="option-2">Option 2</sl-option>
<sl-option value="option-3">Option 3</sl-option>
</sl-select>
```

```jsx:react
import SlIcon from '@shoelace-style/shoelace/dist/react/icon';
import SlOption from '@shoelace-style/shoelace/dist/react/option';
Expand Down
6 changes: 5 additions & 1 deletion src/components/select/select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import type SlOption from '../option/option.component.js';
* @slot - The listbox options. Must be `<sl-option>` elements. You can use `<sl-divider>` to group items visually.
* @slot label - The input's label. Alternatively, you can use the `label` attribute.
* @slot prefix - Used to prepend a presentational icon or similar element to the combobox.
* @slot suffix - Used to append a presentational icon or similar element to the combobox.
* @slot clear-icon - An icon to use in lieu of the default clear icon.
* @slot expand-icon - The icon to show when the control is expanded and collapsed. Rotates on open and close.
* @slot help-text - Text that describes how to use the input. Alternatively, you can use the `help-text` attribute.
Expand All @@ -55,8 +56,9 @@ import type SlOption from '../option/option.component.js';
* @csspart form-control-label - The label's wrapper.
* @csspart form-control-input - The select's wrapper.
* @csspart form-control-help-text - The help text's wrapper.
* @csspart combobox - The container the wraps the prefix, combobox, clear icon, and expand button.
* @csspart combobox - The container the wraps the prefix, suffix, combobox, clear icon, and expand button.
* @csspart prefix - The container that wraps the prefix slot.
* @csspart suffix - The container that wraps the suffix slot.
* @csspart display-input - The element that displays the selected option's label, an `<input>` element.
* @csspart listbox - The listbox container where options are slotted.
* @csspart tags - The container that houses option tags when `multiselect` is used.
Expand Down Expand Up @@ -862,6 +864,8 @@ export default class SlSelect extends ShoelaceElement implements ShoelaceFormCon
`
: ''}
<slot name="suffix" part="suffix" class="select__suffix"></slot>
<slot name="expand-icon" part="expand-icon" class="select__expand-icon">
<sl-icon library="system" name="chevron-down"></sl-icon>
</slot>
Expand Down
8 changes: 8 additions & 0 deletions src/components/select/select.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,14 @@ export default css`
color: var(--sl-input-placeholder-color);
}
/* Suffix */
.select__suffix {
flex: 0;
display: inline-flex;
align-items: center;
color: var(--sl-input-placeholder-color);
}
/* Clear button */
.select__clear {
display: inline-flex;
Expand Down

0 comments on commit dbd4ba8

Please sign in to comment.