TextField error in console in FluentUI React
Asked Answered
R

1

0

I am using TextField component provided by Fluent UI in React wherein I am rendering a custom validation error message (JSX.Element).

 <TextField
    value={"ABC"}
    onChange={(_, newValue: string | undefined) =>                   
             onValueChange(newValue)}
    errorMessage={item.validationError|| undefined}
 />;

The validation error (referred to as item.validationError in above code) is a JSX element which makes use of the Stack component provided by Fluent UI. Pseudo code -

<Stack horizontal horizontalAlign="start">
   <Stack.Item> {} </Stack.Item>
   <Stack.Item> {} </Stack.Item>
</Stack>

For some reason, whenever validation error comes up, this error comes up in console - strong text

It's not impacting the functionality in any way, but how can this error be removed and why is it coming ? I am suspecting this is because Stack is being used inside the TextField component and Stack internally uses div whereas TextField uses p tag.

Rachellerachis answered 2/4, 2023 at 7:47 Comment(0)
L
1

The warning is printed by your browser that checks for certain kind of HTML nesting rules. E.g. block elements should not appear as children of inline elements.

p should only contain inline elements. But a div is a block element.

Your Stack component uses a div element. That is why you see the warning.

Inline and block elements have different attributes. One of the most significant is that block elements take always 100% width.

I don't know the UI library you are using but maybe you can use a different tag for the Stack.

See also: https://stackoverflow.com/a/41928635

Loidaloin answered 2/4, 2023 at 8:3 Comment(2)
Can you edit your answer ? Some parts of your answer seem to be missing. Do you mean p is an inline element and div is a block element ?Rachellerachis
Thanks. Updated my post. Didn't see that the content was escaped as HTML content.Loidaloin

© 2022 - 2024 — McMap. All rights reserved.