Skip to content

Commit a5665cb

Browse files
authored
fix(input): correctly setting initial counter value (#2732)
1 parent 26b620e commit a5665cb

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

packages/db-ui-elements-stencil/src/components/db-input/__tests__/db-input.spec.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ describe('db-input', () => {
2424
const page = await newSpecPage({
2525
components: [DbInput],
2626
html: `
27-
<db-input ariainvalid="_ariainvalid_" ariarequired="true" autocomplete="on" autofocus dirname="_dirname_" disabled input_id="_input_id_" label="_label_" list="_list_" maxlength="2" minlength="5" name="_name_" pattern="_pattern_" placeholder="_placeholder_" readonly required size="2" value="_value_">
27+
<db-input ariainvalid="_ariainvalid_" ariarequired="true" autocomplete="on" autofocus dirname="_dirname_" disabled input_id="_input_id_" label="_label_" list="_list_" maxlength="10" minlength="5" name="_name_" pattern="_pattern_" placeholder="_placeholder_" readonly required size="2" value="_value_">
2828
<option>_option1_</option>
2929
<option>_option2_</option>
3030
</db-input>
3131
`
3232
});
3333
expect(page.root).toEqualHtml(`
34-
<db-input ariainvalid="_ariainvalid_" ariarequired="true" autocomplete="on" autofocus dirname="_dirname_" disabled input_id="_input_id_" label="_label_" list="_list_" maxlength="2" minlength="5" name="_name_" pattern="_pattern_" placeholder="_placeholder_" readonly required size="2" type='text' value="_value_" variant='semitransparent'>
35-
<input aria-invalid="_ariainvalid_" aria-required="true" type="text" class="elm-input" id="_input_id_" autocomplete="on" autofocus data-dirname="_dirname_" disabled list="_list_" maxlength="2" minlength="5" name="_name_" pattern="_pattern_" placeholder="_placeholder_" readonly required size="2" value="_value_" aria-labelledby="_input_id_-label" data-variant='semitransparent' />
36-
<label class="elm-label" htmlFor="_input_id_" aria-hidden="true" id="_input_id_-label">_label_</label><output htmlfor="_input_id_" id="_input_id_-result">0 / 2</output>
34+
<db-input ariainvalid="_ariainvalid_" ariarequired="true" autocomplete="on" autofocus dirname="_dirname_" disabled input_id="_input_id_" label="_label_" list="_list_" maxlength="10" minlength="5" name="_name_" pattern="_pattern_" placeholder="_placeholder_" readonly required size="2" type='text' value="_value_" variant='semitransparent'>
35+
<input aria-invalid="_ariainvalid_" aria-required="true" type="text" class="elm-input" id="_input_id_" autocomplete="on" autofocus data-dirname="_dirname_" disabled list="_list_" maxlength="10" minlength="5" name="_name_" pattern="_pattern_" placeholder="_placeholder_" readonly required size="2" value="_value_" aria-labelledby="_input_id_-label" data-variant='semitransparent' />
36+
<label class="elm-label" htmlFor="_input_id_" aria-hidden="true" id="_input_id_-label">_label_</label><output htmlfor="_input_id_" id="_input_id_-result">7 / 10</output>
3737
<datalist id="_list_">
3838
<option>_option1_</option>
3939
<option>_option2_</option>

packages/db-ui-elements-stencil/src/components/db-input/db-input.tsx

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
12
import { Component, Event, h, Host, Prop, State } from '@stencil/core';
23
import { uuid } from '../../utils/utils';
34

@@ -9,6 +10,8 @@ import { uuid } from '../../utils/utils';
910
export class DbInput {
1011
@State() valueSize = 0;
1112

13+
private inputElement!: HTMLInputElement;
14+
1215
/**
1316
* The ariainvalid attribute is used to indicate that the value entered into an input field does not conform to the format expected by the application.
1417
*/
@@ -151,6 +154,10 @@ export class DbInput {
151154
*/
152155
@Event() dbChange;
153156

157+
componentDidRender() {
158+
this.valueSize = this.inputElement?.value?.length || 0;
159+
}
160+
154161
render() {
155162
return (
156163
<Host>
@@ -183,6 +190,7 @@ export class DbInput {
183190
onInput={(event) => {
184191
this.valueSize = (event.target as HTMLInputElement).value.length;
185192
}}
193+
ref={(el) => (this.inputElement = el as HTMLInputElement)}
186194
/>
187195

188196
<label

0 commit comments

Comments
 (0)