Skip to content

Commit

Permalink
fix: add enable counter for fluid text input (#18281)
Browse files Browse the repository at this point in the history
* fix: add enable counter for text input

* fix: snapshots
  • Loading branch information
riddhybansal authored Feb 11, 2025
1 parent 32f0e85 commit affc44d
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 8 deletions.
6 changes: 6 additions & 0 deletions packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10862,6 +10862,9 @@ Map {
"disabled": Object {
"type": "bool",
},
"enableCounter": Object {
"type": "bool",
},
"id": Object {
"isRequired": true,
"type": "string",
Expand All @@ -10879,6 +10882,9 @@ Map {
"isRequired": true,
"type": "node",
},
"maxCount": Object {
"type": "number",
},
"onChange": Object {
"type": "func",
},
Expand Down
20 changes: 20 additions & 0 deletions packages/react/src/components/FluidTextInput/FluidTextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ export interface FluidTextInputProps {
*/
isPassword?: boolean;

/**
* Max character count allowed for the textInput. This is needed in order for enableCounter to display
*/
maxCount?: number;

/**
* Specify whether to display the character counter
*/
enableCounter?: boolean;

/**
* Provide the text that will be read by a screen reader when visiting this
* control
Expand Down Expand Up @@ -147,6 +157,16 @@ FluidTextInput.propTypes = {
*/
isPassword: PropTypes.bool,

/**
* Max character count allowed for the textInput. This is needed in order for enableCounter to display
*/
maxCount: PropTypes.number,

/**
* Specify whether to display the character counter
*/
enableCounter: PropTypes.bool,

/**
* Provide the text that will be read by a screen reader when visiting this
* control
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/components/TextArea/TextArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ const TextArea = React.forwardRef((props: TextAreaProps, forwardRef) => {

const counterClasses = classNames(`${prefix}--label`, {
[`${prefix}--label--disabled`]: disabled,
[`${prefix}--text-area__label-counter`]: true,
});

const helperTextClasses = classNames(`${prefix}--form__helper-text`, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,21 @@
align-items: center;
margin: 0;
block-size: convert.to-rem(16px);
inline-size: auto;
inset-block-start: convert.to-rem(13px);
inset-inline-start: $spacing-05;

// For the main label
&:not(.#{$prefix}--text-area__label-counter) {
inline-size: auto;
inset-inline-end: auto;
inset-inline-start: $spacing-05;
}

// For the counter
&.#{$prefix}--text-area__label-counter {
inline-size: auto;
inset-inline-end: $spacing-05;
inset-inline-start: auto;
}
}

.#{$prefix}--text-area--fluid .#{$prefix}--label::-webkit-scrollbar,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,21 @@
align-items: center;
margin: 0;
block-size: convert.to-rem(16px);
inline-size: calc(100% - 2rem);
inset-block-start: convert.to-rem(13px);
inset-inline-start: $spacing-05;

// For the main label
&:not(.#{$prefix}--text-input__label-counter) {
inline-size: auto;
inset-inline-end: auto;
inset-inline-start: $spacing-05;
}

// For the counter
&.#{$prefix}--text-input__label-counter {
inline-size: auto;
inset-inline-end: $spacing-05;
inset-inline-start: auto;
}
}

.#{$prefix}--text-input--fluid .#{$prefix}--label::-webkit-scrollbar,
Expand Down
1 change: 1 addition & 0 deletions packages/styles/scss/components/text-area/_text-area.scss
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@
}

.#{$prefix}--text-area__label-wrapper {
position: relative;
display: flex;
justify-content: space-between;
inline-size: 100%;
Expand Down
4 changes: 0 additions & 4 deletions packages/styles/scss/components/text-input/_text-input.scss
Original file line number Diff line number Diff line change
Expand Up @@ -534,9 +534,5 @@
display: flex;
justify-content: space-between;
inline-size: 100%;

.#{$prefix}--text-input__label-counter {
align-self: end;
}
}
}

0 comments on commit affc44d

Please sign in to comment.