Skip to content

Commit f3177d4

Browse files
authored
feat(db-input): added counter (#2500)
* refactor: updated DB UI Core * feat: added counter * refactor: updating DB UI Core * refactor: introducing CSS Anchor positioning * refactor: prevent TS errors * refactor: update DB UI Core * refactor: overwrite styling as we have a grouping HTML tag here
1 parent 5656d12 commit f3177d4

File tree

7 files changed

+44
-7
lines changed

7 files changed

+44
-7
lines changed

package-lock.json

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

packages/db-ui-elements-stencil/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"puppeteer": "^22.6.2"
4646
},
4747
"dependencies": {
48-
"@db-ui/core": "^2.18.2"
48+
"@db-ui/core": "^2.19.2"
4949
},
5050
"license": "Apache-2.0",
5151
"publishConfig": {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('db-input', () => {
3333
expect(page.root).toEqualHtml(`
3434
<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'>
3535
<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>
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>
3737
<datalist id="_list_">
3838
<option>_option1_</option>
3939
<option>_option2_</option>

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,17 @@
55
// Overwriting the referenced SVG icon as this is going to get inlined and the path would be relative to the pages URL instead of the CSS, which would break
66
--db-ic-search-24: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAV9JREFUSEu1le0xBEEURc9GgAjIABkQATIgAyEIQQaIABkQARlYESAC6qjXVV1T3f22dme7an5Nzzv3vq9ZsOWz2HJ8RoBL4Aw4AXaBb+AFeAIeVhXWAhwAj8DRIMg7cAEsM9AUYPC3UPwDXAMG89HFOXAD7Iej03jX5UwBBjoEXiOYaZkeQfeRPu8fj1zUAHN+B6hcJ63gJZYQg+vkKoBNTg2weBZ1+EEVpQh6DrcpQMU7YVl12dHFV1zqdmP94je73CCm39SA4mAvyX/h2MZ23GfULE3RujWw4xzGFFCK5vDYelkXfcRsrNxFKihz4EpwUntz4KSreqjegK1JFmI36cSptQ0FmXOH8DaUF0FOc9dtbxdZD4P1jsptU+8oqAvJtqm7x+Hz2C26ck34CDCVQ8im/4MUsilAZ0PIHIAhZC7AFGJtLPzwl5ktu9b7ki7b9n+653SQrop1FKff/AH2BVIZMfA02AAAAABJRU5ErkJggg==');
77
}
8+
9+
.elm-input:is(
10+
[type='email'],
11+
[type='password'],
12+
[type='search'],
13+
[type='tel'],
14+
[type='text'],
15+
[type='url']
16+
)
17+
+ label
18+
+ output:not(:has(+ .description)) {
19+
float: right;
20+
position: initial;
21+
}

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Event, h, Host, Prop } from '@stencil/core';
1+
import { Component, Event, h, Host, Prop, State } from '@stencil/core';
22
import { uuid } from '../../utils/utils';
33

44
@Component({
@@ -7,6 +7,8 @@ import { uuid } from '../../utils/utils';
77
scoped: true
88
})
99
export class DbInput {
10+
@State() valueSize = 0;
11+
1012
/**
1113
* 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.
1214
*/
@@ -178,6 +180,9 @@ export class DbInput {
178180
aria-labelledby={this.input_id + '-label'}
179181
data-variant={this.variant}
180182
onChange={(event) => this.handleChange(event)}
183+
onInput={(event) => {
184+
this.valueSize = event.target.value.length;
185+
}}
181186
/>
182187

183188
<label
@@ -189,6 +194,11 @@ export class DbInput {
189194
>
190195
{this.label}
191196
</label>
197+
{this.maxlength && (
198+
<output htmlFor={this.input_id} id={`${this.input_id}-result`}>
199+
{`${this.valueSize} / ${this.maxlength}`}
200+
</output>
201+
)}
192202
{this.description && (
193203
<p id={this.input_id + '-hint'} class="description">
194204
{this.description}

packages/db-ui-elements-stencil/src/components/db-input/stories/db-input.intro.stories.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,12 @@ You could set the attribute `label-hidden="true"` for the rare case that you wou
117117
<db-input label="Semitransparent" label-hidden="true"></db-input>
118118
</Canvas>
119119

120+
<db-headline variant="2">maxlength with counter</db-headline>
121+
122+
On providing the maxlength attribute, a counter will be shown below the input field.
123+
124+
<Canvas>
125+
<db-input label="maxlength example" maxlength="100"></db-input>
126+
</Canvas>
127+
120128
<Markdown>{Readme}</Markdown>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
@import '../general';
22
@import 'textarea';
3+
4+
.elm-textarea + output:not(:has(+ .description)) {
5+
float: right;
6+
position: initial;
7+
}

0 commit comments

Comments
 (0)