Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change how show() and hide() work #4

Closed
morrisjdev opened this issue Oct 14, 2019 · 7 comments
Closed

Change how show() and hide() work #4

morrisjdev opened this issue Oct 14, 2019 · 7 comments

Comments

@morrisjdev
Copy link

When doing this on an input element:

$('input').hide().show();

the styling of the input gets destroyed.

Unbenannt

This is because the show method adds the display: block css property. But this changes the behavior of an inline-element for example and because of this cannot be used always.

Can you instead add and remove a hide-class (I am currently fixing it using .addClass('d-none')) or just remove the css-display-styling?

@olton
Copy link
Owner

olton commented Oct 14, 2019

Show full context of your code. Metro version? You use jQuery?

@morrisjdev
Copy link
Author

Sorry for the lack of details.

The metro version of the npm-package is 4.3.1 and i'm not using jQuery.

The setup to reproduce is pretty easy.

HTML:

<div>
<input type='text' data-role='input' />
</div>

JS:

$('input').show().hide();

@morrisjdev
Copy link
Author

And my current fix is to use this snippet to show and hide the objects:

public static hide(object: any) {
    object.addClass('d-none');
  }

  public static show(object: any) {
    object.removeClass('d-none');
  }

@olton
Copy link
Owner

olton commented Oct 14, 2019

$('input').closest(".input").show().hide();

@olton
Copy link
Owner

olton commented Oct 14, 2019

Input component is comlex element. After add role input to element, metro add wrapper and additional elements. To hide component, you must hide wrapper.

@olton
Copy link
Owner

olton commented Oct 14, 2019

If method show can get display value from element, then uses it. You can add specific display value before using show/hide to use this value.

@morrisjdev
Copy link
Author

Ok thank you.
Yes i figured it out, but I think it would be an improvement to reduce the error probability if you just completely remove the display property by default.

@olton olton closed this as completed Oct 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants