[Bug Report] VInput: outlined fieldset legend clipped when dynamically shown
Versions and Environment
Vuetify: 2.0.0-beta.1 Vue: 2.6.10 Browsers: Chrome 74.0.3729.131 OS: Linux x86_64
Steps to reproduce
-
Create an outlined
VTextField,VTextareaorVSelectwith a default value so that the fieldset legend is initially set/shown at the top. -
Place the previously created element in a wrapper with
display: none. -
Dynamically (through JavaScript) change the wrapper style to
display: block.
Expected Behavior
The fieldset legend will have a width in pixels corresponding to the fieldset legend text width. This makes the outlined border not "strike" the fieldset legend text.
Actual Behavior
The fieldset legend will have a width of 6px regardless after the wrapper style is dynamically changed, thus making it appear "clipped" with the outlined border.
Reproduction Link
This is because of how we calculate the dimensions of the label - offsetWidth is 0 when it's hidden. Probably could be done by creating a visible copy of the label, but that could be inefficient with a large amount of inputs, I'd say this is won't fix and advise to use v-if instead of hiding the fields with css
Yes, it's true that in most cases v-if would solve the current issue. However, there are cases where you don't want to use v-if, such as preserving the "state" of the wrapper content while hiding the wrapper (it could contain nested Vue components).
Very related is the following issue, where v-if is used to show/hide the wrapper but the label property is dynamically changed after the fieldset legend has been rendered: https://codepen.io/anon/pen/agOzJv
A visible copy of the label sounds like a workaround and, as you suggest, should probably be avoided. I haven't studied the code behind this but maybe the calculation of the dimensions should be revisited to be more flexible?
Before first showing you don't need any state, possible workaround: https://codepen.io/anon/pen/zVGxbB
Edit: that of course does not fix the problem with changing the label while it's hidden
Take for an example: a "Vuetify form builder" (this is in fact what I'm building in my application) where a user-provided JSON-string is parsed and rendered as a Vuetify-form with different elements utilizing VTextField. It is currently impossible to dynamically render the final VTextField element without running into issues with clipping fieldset legends.
Beyond the suggestion that @jacekkarczmarczyk provided, you could also use a dynamic key to force re-rendering of the inputs. This will also retain the state of the inner items.
https://codepen.io/johnjleider/pen/rExOod
Otherwise, there is not much we can do.
If you have any additional questions, please reach out to us in our Discord community.
Thanks for all input, using a dynamic key solves the issue :smile:
Team,
I am having this problem using inputs inside <v-window>. I have tried the v-if and dynamic key hack but it doesn't seem to be working. I am assuming because the label is calculated while it is still transitioning. The only way I can come up with is a showContent value toggled using a timeout. But that is getting pretty hacky and difficult to manage. Putting inputs inside a window doesn't seem out of pattern is there a better way to manage this.
https://codepen.io/pklitscher/pen/gVvjwZ?editors=1010
Same problem if the input fields are within an <iframe>.
Same issue inside v-stepper
Same thing with expansion panel. And even when using the v-if, it's still clashing/collapse'ing into the label.
I have dynamically generated expansion panels with v-for, and even if I make the v-if based on the index in v-expansion-panel v-model (didn't find any other good way) it still clashes.
I have form elements in every expansion panel content that I wanted visible upon opening.
example: https://codepen.io/Alluuu/pen/OJJbbOm open the panel by clicking on it
Tried also to make the key dependent by the opening state:
<v-expansion-panels v-model="openTab">
and
<v-expansion-panel-content>
<div v-for="(field, index) in baseFields" :key="index + '-' + openTab">
<v-text-field
...
But all it did was slow down (complete lagging) the opening and closing process, but clashing remained
My workaround was inspired by this similar Material-UI issue, where one suggestion was to make the label border white.
Using this Stackoverflow answer as guidance, I have this scoped styling:
>>>label{
background-color:white
}
Same issue inside v-stepper
@BenjaminBorlet, try this.
<v-stepper-items> <v-stepper-content step="1"> <div v-if="step == 1" /> </v-stepper-content> <v-stepper-content step="2"> <div v-if="step == 2" /> </v-stepper-content> <v-stepper-content step="3"> <div v-if="step == 3" /> </v-stepper-content> </v-stepper-items>
@mahammad8564 I just use :key and it's all good, but thank you
@TrobbinsForNow your temporal fix works for me for now. I would love a permanent fix but let me use this for now. Thanks
I had the same problem and I fix it setting the v-text-field initial value in the mounted().
Note that there are some undesired results that seam related to this issue when introducing the prepend-inner-icon attribute too:
https://codepen.io/spencercap/pen/vYYbbqg

^^^ I am experiencing what @spencercap
I'm having the same problem with v-text-field with dynamic label in tabs. Tried to add key on v-text-field but didn't really help. Any help how to fix this, would be really appreciated.
<v-tab-item key="tab-item-pick" value="tab-pick">
<v-text-field autofocus hide-details :loading="urlLoading" v-model="selectedImageNodeSrc" :label="$t('href_link')" outlined clearable></v-text-field>
</v-tab-item>

@danielchodusov looks like you just need some padding or margin between your tabs items and content. (not a text-field issue)