vuetify icon indicating copy to clipboard operation
vuetify copied to clipboard

[Bug Report] VInput: outlined fieldset legend clipped when dynamically shown

Open Pwntus opened this issue 7 years ago • 24 comments

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

  1. Create an outlined VTextField, VTextarea or VSelect with a default value so that the fieldset legend is initially set/shown at the top.

  2. Place the previously created element in a wrapper with display: none.

  3. 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

https://codepen.io/anon/pen/mZyEmE

Pwntus avatar Jun 11 '19 21:06 Pwntus

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

jacekkarczmarczyk avatar Jun 12 '19 05:06 jacekkarczmarczyk

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?

Pwntus avatar Jun 12 '19 15:06 Pwntus

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

jacekkarczmarczyk avatar Jun 12 '19 16:06 jacekkarczmarczyk

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.

Pwntus avatar Jun 12 '19 16:06 Pwntus

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.

johnleider avatar Jun 14 '19 15:06 johnleider

Thanks for all input, using a dynamic key solves the issue :smile:

Pwntus avatar Jun 14 '19 16:06 Pwntus

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

pklitscher avatar Aug 07 '19 09:08 pklitscher

Same problem if the input fields are within an <iframe>.

n3ps avatar Sep 19 '19 18:09 n3ps

Same issue inside v-stepper

BenjaminBorlet avatar Oct 02 '19 08:10 BenjaminBorlet

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

Alluuu avatar Oct 19 '19 12:10 Alluuu

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

Alluuu avatar Oct 19 '19 12:10 Alluuu

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 
    }

Trobbdor avatar Oct 22 '19 16:10 Trobbdor

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>

mr-mad-e avatar Oct 30 '19 12:10 mr-mad-e

@mahammad8564 I just use :key and it's all good, but thank you

BenjaminBorlet avatar Oct 30 '19 14:10 BenjaminBorlet

@TrobbinsForNow your temporal fix works for me for now. I would love a permanent fix but let me use this for now. Thanks

anjayluh avatar Nov 01 '19 05:11 anjayluh

I had the same problem and I fix it setting the v-text-field initial value in the mounted().

ErneMiralles92 avatar Nov 19 '19 15:11 ErneMiralles92

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

Screen Shot 2019-11-19 at 9 50 50 PM

spencercap avatar Nov 20 '19 05:11 spencercap

^^^ I am experiencing what @spencercap

wendelicious avatar Dec 12 '19 06:12 wendelicious

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>

ezgif-4-22256f5692e2

cur53se avatar Dec 17 '19 12:12 cur53se

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

spencercap avatar Jan 09 '20 09:01 spencercap