Skip to content

Commit d6dbb77

Browse files
authored
Merge pull request #265 from silinternational/develop
v11.3.0
2 parents e960d3f + a857080 commit d6dbb77

File tree

7 files changed

+72
-20
lines changed

7 files changed

+72
-20
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22
All notable changes to this project will be documented in this file.
33
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html), enforced with [semantic-release](https://github.com/semantic-release/semantic-release).
44

5+
## [11.3.0](https://github.com/silinternational/ui-components/compare/v11.2.0...v11.3.0) (2024-04-16)
6+
7+
8+
### Fixed
9+
10+
* **Select:** update to match installed version of material/select ([a739d35](https://github.com/silinternational/ui-components/commit/a739d35b5635c74f3846feb3cee3485e5db2929d))
11+
12+
13+
### Added
14+
15+
* **Select:** Add Select.name for convenient form submission ([8f7380b](https://github.com/silinternational/ui-components/commit/8f7380bcd34df41600d3be7bbe9fafc3187c4df8))
16+
* **Select:** Add Select.required prop ([94bab91](https://github.com/silinternational/ui-components/commit/94bab918ba3a6560c49670622802aa942ee32628))
17+
* **Select:** Add Select.ShowError prop which applies the mdc-select--invalid class to the ([3d8f95d](https://github.com/silinternational/ui-components/commit/3d8f95d4657a1ee99f6900522a3449126790f20e))
18+
19+
520
## [11.2.0](https://github.com/silinternational/ui-components/compare/v11.1.2...v11.2.0) (2024-04-09)
621

722

components/mdc/Select/Select.svelte

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ export let width = '280px'
1515
export let disabled = false
1616
/** @type {string} The ID of the selected option. */
1717
export let selectedID = ''
18+
/** @type {boolean} makes a selection required and adds invalid class when none selected */
19+
export let required = false
20+
/** @type {boolean} applies the mdc-select--invalid class */
21+
export let showError = false
22+
/** @type {string} a name for the hidden input field for form submission*/
23+
export let name = ''
1824
1925
const dispatch = createEventDispatcher()
2026
const labelID = generateRandomID('select-label-')
@@ -61,13 +67,32 @@ afterUpdate(() => {
6167
})
6268
</script>
6369

64-
<div class="mdc-select mdc-select--outlined {$$props.class || ''}" bind:this={element} style="width: {width}">
65-
<div class="mdc-select__anchor" role="button" aria-haspopup="listbox" aria-labelledby="{labelID} {selectedTextID}">
70+
<div
71+
class="mdc-select mdc-select--outlined {$$props.class || ''}"
72+
class:mdc-select--required={required}
73+
class:mdc-select--invalid={showError}
74+
bind:this={element}
75+
style="width: {width}"
76+
>
77+
<input {required} type="hidden" {name} />
78+
<div
79+
class="mdc-select__anchor"
80+
aria-required={required}
81+
aria-haspopup="listbox"
82+
aria-labelledby="{labelID} {selectedTextID}"
83+
>
84+
<span class="mdc-notched-outline">
85+
<span class="mdc-notched-outline__leading" />
86+
<span class="mdc-notched-outline__notch">
87+
<span id={labelID} class="mdc-floating-label">{label}</span>
88+
</span>
89+
<span class="mdc-notched-outline__trailing" />
90+
</span>
6691
<span class="mdc-select__selected-text-container">
6792
<span id={selectedTextID} class="mdc-select__selected-text" />
6893
</span>
6994
<span class="mdc-select__dropdown-icon">
70-
<svg class="mdc-select__dropdown-icon-graphic" viewBox="7 10 10 5">
95+
<svg class="mdc-select__dropdown-icon-graphic" viewBox="7 10 10 5" focusable="false">
7196
<polygon
7297
class="mdc-select__dropdown-icon-inactive"
7398
stroke="none"
@@ -77,17 +102,10 @@ afterUpdate(() => {
77102
<polygon class="mdc-select__dropdown-icon-active" stroke="none" fill-rule="evenodd" points="7 15 12 10 17 15" />
78103
</svg>
79104
</span>
80-
<span class="mdc-notched-outline">
81-
<span class="mdc-notched-outline__leading" />
82-
<span class="mdc-notched-outline__notch">
83-
<span id={labelID} class="mdc-floating-label">{label}</span>
84-
</span>
85-
<span class="mdc-notched-outline__trailing" />
86-
</span>
87105
</div>
88106

89-
<div class="mdc-select__menu mdc-menu mdc-menu-surface" style="width: {width}" role="listbox">
90-
<ul class="mdc-deprecated-list">
107+
<div class="mdc-select__menu mdc-menu mdc-menu-surface mdc-menu-surface--fullwidth">
108+
<ul class="mdc-deprecated-list" role="listbox" aria-label={label + ' picker listbox'}>
91109
{#each options as { id, name } (id)}
92110
<li class="mdc-deprecated-list-item" data-value={id} role="option" aria-selected={isOptionSelected(id)}>
93111
<span class="mdc-deprecated-list-item__text">{name}</span>

components/mdc/Select/_index.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
@use '@material/select/styles';
55

66
/* MDC select floating label */
7-
.mdc-select:not(.mdc-select--disabled).mdc-select--focused .mdc-floating-label {
7+
.mdc-select:not(.mdc-select--disabled, .mdc-select--invalid).mdc-select--focused .mdc-floating-label {
88
color: var(--mdc-theme-primary);
99
}

index.d.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,14 @@ declare module '@silintl/ui-components' {
235235
}
236236

237237
interface SelectProps {
238+
disabled?: boolean
238239
label?: string
240+
name?: string
239241
options?: { name: string; id: string }[]
240-
width?: string
241-
disabled?: boolean
242+
required?: boolean
243+
showError?: boolean
242244
selectedID?: string
245+
width?: string
243246
class?: string
244247
}
245248
export class Select extends SvelteComponentTyped<SelectProps> {}

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@silintl/ui-components",
3-
"version": "11.2.0",
3+
"version": "11.3.0",
44
"description": "Reusable Svelte components for some internal applications",
55
"main": "index.mjs",
66
"module": "index.mjs",

stories/Select.stories.svelte

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<script>
22
import { Meta, Template, Story } from '@storybook/addon-svelte-csf'
3-
import { Select } from '../components/mdc'
3+
import { Button, Select, Snackbar, setNotice } from '../components/mdc'
44
import { copyAndModifyArgs } from './helpers.js'
5+
import { Form } from '../components/custom'
56
67
const args = {
78
options: [
@@ -21,13 +22,28 @@ const args = {
2122
<Meta title="Atoms/Select" component={Select} />
2223

2324
<Template let:args>
24-
<Select {...args} on:change={args['on:change']} on:populated={args['on:populated']} />
25+
<Form on:submit={(e) => setNotice('submitted')}>
26+
<p>
27+
<Select {...args} on:change={args['on:change']} on:populated={args['on:populated']} />
28+
</p>
29+
<Button raised>Submit</Button>
30+
</Form>
31+
32+
<Snackbar />
2533
</Template>
2634

2735
<Story name="Default" {args} />
2836

37+
<Story name="selectedID" args={copyAndModifyArgs(args, { selectedID: '5' })} />
38+
2939
<Story name="Label" args={copyAndModifyArgs(args, { label: 'Label' })} />
3040

3141
<Story name="Width" args={copyAndModifyArgs(args, { width: '560px' })} />
3242

3343
<Story name="Disabled" args={copyAndModifyArgs(args, { disabled: true })} />
44+
45+
<Story name="required" args={copyAndModifyArgs(args, { required: true })} />
46+
47+
<Story name="showError" args={copyAndModifyArgs(args, { showError: true })} />
48+
49+
<Story name="name" args={copyAndModifyArgs(args, { name: 'category' })} />

0 commit comments

Comments
 (0)