mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 02:11:05 +00:00
breaking(number-input): align change
, input
events with native input
behavior (#1053)
* Closes #1052 * Closes #1050
This commit is contained in:
parent
a8039a4d1e
commit
099efedef1
4 changed files with 25 additions and 15 deletions
|
@ -2600,11 +2600,11 @@ export type NumberInputTranslationId = "increment" | "decrement";
|
||||||
| Event name | Type | Detail |
|
| Event name | Type | Detail |
|
||||||
| :--------- | :--------- | :------------------------------ |
|
| :--------- | :--------- | :------------------------------ |
|
||||||
| change | dispatched | <code>null | number</code> |
|
| change | dispatched | <code>null | number</code> |
|
||||||
|
| input | dispatched | <code>null | number</code> |
|
||||||
| click | forwarded | -- |
|
| click | forwarded | -- |
|
||||||
| mouseover | forwarded | -- |
|
| mouseover | forwarded | -- |
|
||||||
| mouseenter | forwarded | -- |
|
| mouseenter | forwarded | -- |
|
||||||
| mouseleave | forwarded | -- |
|
| mouseleave | forwarded | -- |
|
||||||
| input | forwarded | -- |
|
|
||||||
| focus | forwarded | -- |
|
| focus | forwarded | -- |
|
||||||
| blur | forwarded | -- |
|
| blur | forwarded | -- |
|
||||||
|
|
||||||
|
|
|
@ -7247,11 +7247,11 @@
|
||||||
],
|
],
|
||||||
"events": [
|
"events": [
|
||||||
{ "type": "dispatched", "name": "change", "detail": "null | number" },
|
{ "type": "dispatched", "name": "change", "detail": "null | number" },
|
||||||
|
{ "type": "dispatched", "name": "input", "detail": "null | number" },
|
||||||
{ "type": "forwarded", "name": "click", "element": "div" },
|
{ "type": "forwarded", "name": "click", "element": "div" },
|
||||||
{ "type": "forwarded", "name": "mouseover", "element": "div" },
|
{ "type": "forwarded", "name": "mouseover", "element": "div" },
|
||||||
{ "type": "forwarded", "name": "mouseenter", "element": "div" },
|
{ "type": "forwarded", "name": "mouseenter", "element": "div" },
|
||||||
{ "type": "forwarded", "name": "mouseleave", "element": "div" },
|
{ "type": "forwarded", "name": "mouseleave", "element": "div" },
|
||||||
{ "type": "forwarded", "name": "input", "element": "input" },
|
|
||||||
{ "type": "forwarded", "name": "focus", "element": "input" },
|
{ "type": "forwarded", "name": "focus", "element": "input" },
|
||||||
{ "type": "forwarded", "name": "blur", "element": "input" }
|
{ "type": "forwarded", "name": "blur", "element": "input" }
|
||||||
],
|
],
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
/**
|
/**
|
||||||
* @typedef {"increment" | "decrement"} NumberInputTranslationId
|
* @typedef {"increment" | "decrement"} NumberInputTranslationId
|
||||||
* @event {null | number} change
|
* @event {null | number} change
|
||||||
|
* @event {null | number} input
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -128,20 +129,33 @@
|
||||||
} else {
|
} else {
|
||||||
value = nextValue;
|
value = nextValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dispatch("input", value);
|
||||||
|
dispatch("change", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
let inputValue = value;
|
|
||||||
|
|
||||||
$: dispatch("change", value);
|
|
||||||
$: incrementLabel = translateWithId("increment");
|
$: incrementLabel = translateWithId("increment");
|
||||||
$: decrementLabel = translateWithId("decrement");
|
$: decrementLabel = translateWithId("decrement");
|
||||||
$: value = inputValue != null ? Number(inputValue) : null;
|
|
||||||
$: error =
|
$: error =
|
||||||
invalid || (!allowEmpty && value == null) || value > max || value < min;
|
invalid || (!allowEmpty && value == null) || value > max || value < min;
|
||||||
$: errorId = `error-${id}`;
|
$: errorId = `error-${id}`;
|
||||||
$: ariaLabel =
|
$: ariaLabel =
|
||||||
$$props["aria-label"] ||
|
$$props["aria-label"] ||
|
||||||
"Numeric input field with increment and decrement buttons";
|
"Numeric input field with increment and decrement buttons";
|
||||||
|
|
||||||
|
function parse(raw) {
|
||||||
|
return raw != "" ? Number(raw) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function onInput({ target }) {
|
||||||
|
value = parse(target.value);
|
||||||
|
|
||||||
|
dispatch("input", value);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onChange({ target }) {
|
||||||
|
dispatch("change", parse(target.value));
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- svelte-ignore a11y-mouse-events-have-key-events -->
|
<!-- svelte-ignore a11y-mouse-events-have-key-events -->
|
||||||
|
@ -207,10 +221,8 @@
|
||||||
value="{value ?? ''}"
|
value="{value ?? ''}"
|
||||||
readonly="{readonly}"
|
readonly="{readonly}"
|
||||||
{...$$restProps}
|
{...$$restProps}
|
||||||
on:input
|
on:change="{onChange}"
|
||||||
on:input="{({ target }) => {
|
on:input="{onInput}"
|
||||||
inputValue = target.value;
|
|
||||||
}}"
|
|
||||||
on:focus
|
on:focus
|
||||||
on:blur
|
on:blur
|
||||||
/>
|
/>
|
||||||
|
@ -262,10 +274,8 @@
|
||||||
value="{value ?? ''}"
|
value="{value ?? ''}"
|
||||||
readonly="{readonly}"
|
readonly="{readonly}"
|
||||||
{...$$restProps}
|
{...$$restProps}
|
||||||
on:input
|
on:change="{onChange}"
|
||||||
on:input="{({ target }) => {
|
on:input="{onInput}"
|
||||||
inputValue = target.value;
|
|
||||||
}}"
|
|
||||||
on:focus
|
on:focus
|
||||||
on:blur
|
on:blur
|
||||||
/>
|
/>
|
||||||
|
|
2
types/NumberInput/NumberInput.svelte.d.ts
vendored
2
types/NumberInput/NumberInput.svelte.d.ts
vendored
|
@ -149,11 +149,11 @@ export default class NumberInput extends SvelteComponentTyped<
|
||||||
NumberInputProps,
|
NumberInputProps,
|
||||||
{
|
{
|
||||||
change: CustomEvent<null | number>;
|
change: CustomEvent<null | number>;
|
||||||
|
input: CustomEvent<null | number>;
|
||||||
click: WindowEventMap["click"];
|
click: WindowEventMap["click"];
|
||||||
mouseover: WindowEventMap["mouseover"];
|
mouseover: WindowEventMap["mouseover"];
|
||||||
mouseenter: WindowEventMap["mouseenter"];
|
mouseenter: WindowEventMap["mouseenter"];
|
||||||
mouseleave: WindowEventMap["mouseleave"];
|
mouseleave: WindowEventMap["mouseleave"];
|
||||||
input: WindowEventMap["input"];
|
|
||||||
focus: WindowEventMap["focus"];
|
focus: WindowEventMap["focus"];
|
||||||
blur: WindowEventMap["blur"];
|
blur: WindowEventMap["blur"];
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue