noph-ui 0.17.1 → 0.17.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -29,12 +29,15 @@
29
29
  autofocus,
30
30
  onchange,
31
31
  oninput,
32
+ reportValidity = $bindable(),
33
+ checkValidity = $bindable(),
32
34
  multiple,
33
35
  clampMenuWidth = false,
34
36
  ...attributes
35
37
  }: SelectProps = $props()
36
38
 
37
39
  const uid = $props.id()
40
+ let doValidity = $state(false)
38
41
  if (value === undefined) {
39
42
  if (multiple) {
40
43
  value = options.filter((option) => option.selected).map((option) => option.value)
@@ -74,6 +77,26 @@
74
77
  }
75
78
  return options.find((option) => option.value === value)?.label || ''
76
79
  })
80
+
81
+ reportValidity = () => {
82
+ if (selectElement) {
83
+ const valid = selectElement.reportValidity()
84
+ if (valid) {
85
+ errorRaw = error
86
+ errorTextRaw = errorText
87
+ }
88
+ return valid
89
+ }
90
+ return false
91
+ }
92
+
93
+ checkValidity = () => {
94
+ if (selectElement) {
95
+ return selectElement.checkValidity()
96
+ }
97
+ return false
98
+ }
99
+
77
100
  $effect(() => {
78
101
  errorRaw = error
79
102
  errorTextRaw = errorText
@@ -107,6 +130,10 @@
107
130
  }
108
131
  event.preventDefault()
109
132
  tick().then(() => {
133
+ if (doValidity && checkValidity()) {
134
+ errorRaw = error
135
+ errorTextRaw = errorText
136
+ }
110
137
  selectElement?.dispatchEvent(new Event('change', { bubbles: true }))
111
138
  })
112
139
  }
@@ -222,19 +249,21 @@
222
249
  event.preventDefault()
223
250
  const { currentTarget } = event
224
251
  errorRaw = true
252
+ doValidity = true
225
253
  if (errorText === '') {
226
254
  errorTextRaw = currentTarget.validationMessage
227
255
  }
228
256
  if (isFirstInvalidControlInForm(currentTarget.form, currentTarget)) {
229
257
  field?.focus()
230
- menuElement?.showPopover()
231
258
  }
232
259
  }}
233
260
  bind:value
234
261
  bind:this={selectElement}
235
262
  >
236
263
  {#each selectedOption as option, index (index)}
237
- <option value={option.value} selected={option.selected}>{option.label}</option>
264
+ <option class="np-option" value={option.value} selected={option.selected}
265
+ >{option.label}</option
266
+ >
238
267
  {/each}
239
268
  </select>
240
269
  {:else}
@@ -251,12 +280,12 @@
251
280
  event.preventDefault()
252
281
  const { currentTarget } = event
253
282
  errorRaw = true
283
+ doValidity = true
254
284
  if (errorText === '') {
255
285
  errorTextRaw = currentTarget.validationMessage
256
286
  }
257
287
  if (isFirstInvalidControlInForm(currentTarget.form, currentTarget)) {
258
288
  field?.focus()
259
- menuElement?.showPopover()
260
289
  }
261
290
  }}
262
291
  bind:value
@@ -568,6 +597,12 @@
568
597
  }
569
598
  }
570
599
 
600
+ .np-option {
601
+ width: 0;
602
+ height: 0;
603
+ display: block;
604
+ }
605
+
571
606
  .no-label .content,
572
607
  .field.menu-open .content,
573
608
  .field:focus .content,
@@ -1,4 +1,4 @@
1
1
  import type { SelectProps } from './types.ts';
2
- declare const Select: import("svelte").Component<SelectProps, {}, "element" | "value">;
2
+ declare const Select: import("svelte").Component<SelectProps, {}, "element" | "value" | "reportValidity" | "checkValidity">;
3
3
  type Select = ReturnType<typeof Select>;
4
4
  export default Select;
@@ -18,4 +18,6 @@ export interface SelectProps extends Omit<HTMLSelectAttributes, 'size' | 'autoco
18
18
  element?: HTMLSpanElement;
19
19
  options: SelectOption[];
20
20
  clampMenuWidth?: boolean;
21
+ reportValidity?: () => boolean;
22
+ checkValidity?: () => boolean;
21
23
  }
@@ -1,4 +1,4 @@
1
1
  import type { TextFieldProps } from './types.ts';
2
- declare const TextField: import("svelte").Component<TextFieldProps, {}, "element" | "value" | "inputElement" | "reportValidity" | "checkValidity">;
2
+ declare const TextField: import("svelte").Component<TextFieldProps, {}, "element" | "value" | "reportValidity" | "checkValidity" | "inputElement">;
3
3
  type TextField = ReturnType<typeof TextField>;
4
4
  export default TextField;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "noph-ui",
3
- "version": "0.17.1",
3
+ "version": "0.17.3",
4
4
  "license": "MIT",
5
5
  "homepage": "https://noph.dev",
6
6
  "repository": {