mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 18:31:06 +00:00
fix: readonly
should override error
behavior in TextInput
, NumberInput
(#1666)
* fix(text-input): avoid overlapping readonly/invalid icons * fix(number-input): avoid overlapping readonly/invalid icons * fix: readonly inputs cannot be invalid Addresses https://github.com/carbon-design-system/carbon-components-svelte/pull/1666#pullrequestreview-1314558645
This commit is contained in:
parent
65a8bbf1f9
commit
6386c33f93
2 changed files with 28 additions and 25 deletions
|
@ -128,7 +128,7 @@
|
||||||
$: incrementLabel = translateWithId("increment");
|
$: incrementLabel = translateWithId("increment");
|
||||||
$: decrementLabel = translateWithId("decrement");
|
$: decrementLabel = translateWithId("decrement");
|
||||||
$: error =
|
$: error =
|
||||||
invalid ||
|
(invalid && !readonly) ||
|
||||||
(!allowEmpty && value == null) ||
|
(!allowEmpty && value == null) ||
|
||||||
value > max ||
|
value > max ||
|
||||||
(typeof value === "number" && value < min);
|
(typeof value === "number" && value < min);
|
||||||
|
@ -191,8 +191,8 @@
|
||||||
type="number"
|
type="number"
|
||||||
pattern="[0-9]*"
|
pattern="[0-9]*"
|
||||||
aria-describedby="{errorId}"
|
aria-describedby="{errorId}"
|
||||||
data-invalid="{invalid || undefined}"
|
data-invalid="{(error) || undefined}"
|
||||||
aria-invalid="{invalid || undefined}"
|
aria-invalid="{(error) || undefined}"
|
||||||
aria-label="{label ? undefined : ariaLabel}"
|
aria-label="{label ? undefined : ariaLabel}"
|
||||||
disabled="{disabled}"
|
disabled="{disabled}"
|
||||||
id="{id}"
|
id="{id}"
|
||||||
|
@ -211,16 +211,17 @@
|
||||||
on:blur
|
on:blur
|
||||||
on:paste
|
on:paste
|
||||||
/>
|
/>
|
||||||
{#if invalid}
|
|
||||||
<WarningFilled class="bx--number__invalid" />
|
|
||||||
{/if}
|
|
||||||
{#if !invalid && warn}
|
|
||||||
<WarningAltFilled
|
|
||||||
class="bx--number__invalid bx--number__invalid--warning"
|
|
||||||
/>
|
|
||||||
{/if}
|
|
||||||
{#if readonly}
|
{#if readonly}
|
||||||
<EditOff class="bx--text-input__readonly-icon" />
|
<EditOff class="bx--text-input__readonly-icon" />
|
||||||
|
{:else}
|
||||||
|
{#if invalid}
|
||||||
|
<WarningFilled class="bx--number__invalid" />
|
||||||
|
{/if}
|
||||||
|
{#if !invalid && warn}
|
||||||
|
<WarningAltFilled
|
||||||
|
class="bx--number__invalid bx--number__invalid--warning"
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
{#if !hideSteppers}
|
{#if !hideSteppers}
|
||||||
<div class:bx--number__controls="{true}">
|
<div class:bx--number__controls="{true}">
|
||||||
|
|
|
@ -95,6 +95,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
$: isFluid = !!ctx && ctx.isFluid;
|
$: isFluid = !!ctx && ctx.isFluid;
|
||||||
|
$: error = invalid && !readonly;
|
||||||
$: helperId = `helper-${id}`;
|
$: helperId = `helper-${id}`;
|
||||||
$: errorId = `error-${id}`;
|
$: errorId = `error-${id}`;
|
||||||
$: warnId = `warn-${id}`;
|
$: warnId = `warn-${id}`;
|
||||||
|
@ -161,29 +162,30 @@
|
||||||
class:bx--text-input__field-outer-wrapper--inline="{inline}"
|
class:bx--text-input__field-outer-wrapper--inline="{inline}"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
data-invalid="{invalid || undefined}"
|
data-invalid="{error || undefined}"
|
||||||
data-warn="{warn || undefined}"
|
data-warn="{warn || undefined}"
|
||||||
class:bx--text-input__field-wrapper="{true}"
|
class:bx--text-input__field-wrapper="{true}"
|
||||||
class:bx--text-input__field-wrapper--warning="{!invalid && warn}"
|
class:bx--text-input__field-wrapper--warning="{!invalid && warn}"
|
||||||
>
|
>
|
||||||
{#if invalid}
|
|
||||||
<WarningFilled class="bx--text-input__invalid-icon" />
|
|
||||||
{/if}
|
|
||||||
{#if !invalid && warn}
|
|
||||||
<WarningAltFilled
|
|
||||||
class="bx--text-input__invalid-icon
|
|
||||||
bx--text-input__invalid-icon--warning"
|
|
||||||
/>
|
|
||||||
{/if}
|
|
||||||
{#if readonly}
|
{#if readonly}
|
||||||
<EditOff class="bx--text-input__readonly-icon" />
|
<EditOff class="bx--text-input__readonly-icon" />
|
||||||
|
{:else}
|
||||||
|
{#if invalid}
|
||||||
|
<WarningFilled class="bx--text-input__invalid-icon" />
|
||||||
|
{/if}
|
||||||
|
{#if !invalid && warn}
|
||||||
|
<WarningAltFilled
|
||||||
|
class="bx--text-input__invalid-icon
|
||||||
|
bx--text-input__invalid-icon--warning"
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
<input
|
<input
|
||||||
bind:this="{ref}"
|
bind:this="{ref}"
|
||||||
data-invalid="{invalid || undefined}"
|
data-invalid="{error || undefined}"
|
||||||
aria-invalid="{invalid || undefined}"
|
aria-invalid="{error || undefined}"
|
||||||
data-warn="{warn || undefined}"
|
data-warn="{warn || undefined}"
|
||||||
aria-describedby="{invalid
|
aria-describedby="{error
|
||||||
? errorId
|
? errorId
|
||||||
: warn
|
: warn
|
||||||
? warnId
|
? warnId
|
||||||
|
@ -199,7 +201,7 @@
|
||||||
readonly="{readonly}"
|
readonly="{readonly}"
|
||||||
class:bx--text-input="{true}"
|
class:bx--text-input="{true}"
|
||||||
class:bx--text-input--light="{light}"
|
class:bx--text-input--light="{light}"
|
||||||
class:bx--text-input--invalid="{invalid}"
|
class:bx--text-input--invalid="{error}"
|
||||||
class:bx--text-input--warn="{warn}"
|
class:bx--text-input--warn="{warn}"
|
||||||
class:bx--text-input--sm="{size === 'sm'}"
|
class:bx--text-input--sm="{size === 'sm'}"
|
||||||
class:bx--text-input--xl="{size === 'xl'}"
|
class:bx--text-input--xl="{size === 'xl'}"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue