Skip to content

Commit 5e5bf39

Browse files
authored
fix(base-field): Don't unnecessarily render container below BaseField children (#926)
1 parent 78351a4 commit 5e5bf39

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/base-field/base-field.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -268,14 +268,12 @@ function BaseField({
268268

269269
const ariaDescribedBy = originalAriaDescribedBy ?? (message ? messageId : null)
270270

271-
/**
272-
* Renders the character count element.
273-
* If the characterCountPosition value is 'hidden', it returns null.
274-
*/
271+
const renderCharacterCountBelow = characterCountPosition === 'below' && characterCount !== null
272+
const renderCharacterCountInline =
273+
characterCountPosition === 'inline' && characterCount !== null
274+
275275
function renderCharacterCount() {
276-
return characterCountPosition !== 'hidden' ? (
277-
<FieldCharacterCount tone={characterCountTone}>{characterCount}</FieldCharacterCount>
278-
) : null
276+
return <FieldCharacterCount tone={characterCountTone}>{characterCount}</FieldCharacterCount>
279277
}
280278

281279
const childrenProps: ChildrenRenderProps = {
@@ -297,7 +295,7 @@ function BaseField({
297295
setCharacterCountTone(inputLength.tone)
298296
},
299297
// If the character count is inline, we pass it as a prop to the children element so it can be rendered inline
300-
characterCountElement: characterCountPosition === 'inline' ? renderCharacterCount() : null,
298+
characterCountElement: renderCharacterCountInline ? renderCharacterCount() : null,
301299
}
302300

303301
React.useEffect(
@@ -360,7 +358,7 @@ function BaseField({
360358
{endSlot && endSlotPosition === 'fullHeight' ? endSlot : null}
361359
</Box>
362360

363-
{message || characterCount ? (
361+
{message || renderCharacterCountBelow ? (
364362
<Columns align="right" space="small" maxWidth={maxWidth}>
365363
{message ? (
366364
<Column width="auto">

0 commit comments

Comments
 (0)