Skip to content

Commit affc44d

Browse files
authored
fix: add enable counter for fluid text input (#18281)
* fix: add enable counter for text input * fix: snapshots
1 parent 32f0e85 commit affc44d

File tree

7 files changed

+56
-8
lines changed

7 files changed

+56
-8
lines changed

packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10862,6 +10862,9 @@ Map {
1086210862
"disabled": Object {
1086310863
"type": "bool",
1086410864
},
10865+
"enableCounter": Object {
10866+
"type": "bool",
10867+
},
1086510868
"id": Object {
1086610869
"isRequired": true,
1086710870
"type": "string",
@@ -10879,6 +10882,9 @@ Map {
1087910882
"isRequired": true,
1088010883
"type": "node",
1088110884
},
10885+
"maxCount": Object {
10886+
"type": "number",
10887+
},
1088210888
"onChange": Object {
1088310889
"type": "func",
1088410890
},

packages/react/src/components/FluidTextInput/FluidTextInput.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ export interface FluidTextInputProps {
4949
*/
5050
isPassword?: boolean;
5151

52+
/**
53+
* Max character count allowed for the textInput. This is needed in order for enableCounter to display
54+
*/
55+
maxCount?: number;
56+
57+
/**
58+
* Specify whether to display the character counter
59+
*/
60+
enableCounter?: boolean;
61+
5262
/**
5363
* Provide the text that will be read by a screen reader when visiting this
5464
* control
@@ -147,6 +157,16 @@ FluidTextInput.propTypes = {
147157
*/
148158
isPassword: PropTypes.bool,
149159

160+
/**
161+
* Max character count allowed for the textInput. This is needed in order for enableCounter to display
162+
*/
163+
maxCount: PropTypes.number,
164+
165+
/**
166+
* Specify whether to display the character counter
167+
*/
168+
enableCounter: PropTypes.bool,
169+
150170
/**
151171
* Provide the text that will be read by a screen reader when visiting this
152172
* control

packages/react/src/components/TextArea/TextArea.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ const TextArea = React.forwardRef((props: TextAreaProps, forwardRef) => {
352352

353353
const counterClasses = classNames(`${prefix}--label`, {
354354
[`${prefix}--label--disabled`]: disabled,
355+
[`${prefix}--text-area__label-counter`]: true,
355356
});
356357

357358
const helperTextClasses = classNames(`${prefix}--form__helper-text`, {

packages/styles/scss/components/fluid-text-area/_fluid-text-area.scss

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,21 @@
4242
align-items: center;
4343
margin: 0;
4444
block-size: convert.to-rem(16px);
45-
inline-size: auto;
4645
inset-block-start: convert.to-rem(13px);
47-
inset-inline-start: $spacing-05;
46+
47+
// For the main label
48+
&:not(.#{$prefix}--text-area__label-counter) {
49+
inline-size: auto;
50+
inset-inline-end: auto;
51+
inset-inline-start: $spacing-05;
52+
}
53+
54+
// For the counter
55+
&.#{$prefix}--text-area__label-counter {
56+
inline-size: auto;
57+
inset-inline-end: $spacing-05;
58+
inset-inline-start: auto;
59+
}
4860
}
4961

5062
.#{$prefix}--text-area--fluid .#{$prefix}--label::-webkit-scrollbar,

packages/styles/scss/components/fluid-text-input/_fluid-text-input.scss

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,21 @@
3333
align-items: center;
3434
margin: 0;
3535
block-size: convert.to-rem(16px);
36-
inline-size: calc(100% - 2rem);
3736
inset-block-start: convert.to-rem(13px);
38-
inset-inline-start: $spacing-05;
37+
38+
// For the main label
39+
&:not(.#{$prefix}--text-input__label-counter) {
40+
inline-size: auto;
41+
inset-inline-end: auto;
42+
inset-inline-start: $spacing-05;
43+
}
44+
45+
// For the counter
46+
&.#{$prefix}--text-input__label-counter {
47+
inline-size: auto;
48+
inset-inline-end: $spacing-05;
49+
inset-inline-start: auto;
50+
}
3951
}
4052

4153
.#{$prefix}--text-input--fluid .#{$prefix}--label::-webkit-scrollbar,

packages/styles/scss/components/text-area/_text-area.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@
235235
}
236236

237237
.#{$prefix}--text-area__label-wrapper {
238+
position: relative;
238239
display: flex;
239240
justify-content: space-between;
240241
inline-size: 100%;

packages/styles/scss/components/text-input/_text-input.scss

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -534,9 +534,5 @@
534534
display: flex;
535535
justify-content: space-between;
536536
inline-size: 100%;
537-
538-
.#{$prefix}--text-input__label-counter {
539-
align-self: end;
540-
}
541537
}
542538
}

0 commit comments

Comments
 (0)