How to correctly nest slots in child elements when using Stencil.js? - web-component

I know that if I have a <slot /> inside my component, I can then insert content from the HTML, but I don't understand how this works.
For example:
render() {
return(
<div>
<slot />
</div>
)
}
Now, inside my HTML, I can do this:
<my-card>test</my-card>
and "test" will be inserted as a content.
However, if the <slot /> is nested inside other child-elements inside my component, the "test" text is still inserted even if it's not inside those particular elements. How does that work?
For example:
render() {
return(
<div>
<button><slot /></button>
<select>
<option value="one"><slot /></option>
</select>
<p><slot /></p>
</div>
)
}
Now, in my HTML, if I do this:
<my-card>test</my-card>
The text "test" is inserted inside the <slot /> inside the button. But what if I want to add text inside the <option> <slot />? How do I do that?
If I only have one <slot /> inside <option> for example, how do I insert text inside of it from my HTML?

As mentioned in the comments, you can only have a single unnamed slot. Any additional slots have to have a name:
<slot name="outside" />
To add an element inside a named slot you can use the slot attribute:
<my-card>
<span slot="outside">test</span>
</my-card>
See also Stencil's documentation on slots.

Related

How to target and change in CSS a class element from (react.js) Formik?

How would one target an element which is part of Formik and has the jsx-prefix?
HTML:
<p>
{isMyProfile ? (
<UserName />
) : (
<PageHeading>
{user?.firstname} {user?.lastname}
</PageHeading>
)}
</p>
CSS:
<button type="button" class="jsx-962024717 jsx-380790680 plain-button">
I got this CSS code from dev.tools, but I am not able to change the CSS of this element and target the UserName and PageHeading.

Force browser to display Element as text

I got this weird problem:
I get content that is dynamically built. In this special case I also get the element "input" as content, which is then displayed directly by the browser as an element.
What I get:
<div class="search_result_content"> this is just text, but the code <input variable="" name=""> displays as an element
What i need:
You may want to add 'type="text"', so total would be like
<input type="text" name="" value=""/>
Else if the input needs to be added to a (like) 'span' or 'div', i would suggest JS or jQuery
$(document).ready(function() {
$(".search_result_content").append('<input variable="" name="">');
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="search_result_content"> this is just text, but the code </div>
u insert the input tag dynamically in this scenario, after inserting convert it into html format

Vue not applying styles when inserting with v-for directive

I'm using a paid template, and I'm trying to apply it to the project (it's working, but not good to the eye)
This is the code
<input type="checkbox" name="checkbox_demo_mars" id="checkbox_demo_4" data-md-icheck checked />
<label for="checkbox_demo_4" class="inline-label">Outside vue</label>
<div id="vm_settings">
<input type="checkbox" name="checkbox_demo_mars" id="checkbox_demo_4" data-md-icheck checked />
<label for="checkbox_demo_4" class="inline-label">Inside VM</label>
<template v-if="1">
<input type="checkbox" name="checkbox_demo_mars" id="checkbox_demo_4" data-md-icheck checked />
<label for="checkbox_demo_4" class="inline-label">Inside if</label>
</template>
<template v-for="setting in settings">
<div>
<input type="checkbox" name="checkbox_demo_mars" id="checkbox_demo_4" data-md-icheck checked />
<label for="checkbox_demo_4" class="inline-label">Inside for</label>
</div>
</template>
<button v-on:click="saveSettings">Save</button>
</div>
This is how it is outputed to the browser checkbox not having the styles it should
Any way to fix it?
Customized checkboxes are not merely styled with CSS, they are proxied: the real checkbox widget is hidden and other elements are inserted and styled in their place.
As such, there must be some call that examines the HTML and does the widget replacement. You need that to happen to each element that gets inserted. You do that by writing a wrapper component. Typically, in its mounted hook, you would apply the initialization of the widget to this.$el (or something inside it).

Angular 4 - access formControl state through ng-content

I want to create custom styling for my form elements. Therefore I have to add a parent element to each input and select element. The parent element will contain the CSS classes for the styling. Example:
<div class="o-form-field is-valid">
<input formControlName="foo">
</div>
<div class="o-form-field is-invalid">
<input formControlName="bar">
</div>
<div class="o-form-field has-error">
<input formControlName="baz">
</div>
I am looking for a solution where I can replace the outer DIV with a component that watched the child input state and figures out what classes are needed. Renders the DIV in it's template and transcludes the input element. So my form template would look something like this.
<form-field-container>
<input formControlName="foo">
</form-field-container>
<form-field-container>
<input formControlName="bar">
</form-field>
<form-field-container>
<input formControlName="baz">
</form-field>
I am using Reactive forms.

How to set a hidden style to a spring:message tag

I am using the spring:message tag to basically display a label over an input field.
Example:
<div class="col-md-3">
<spring:message code="referral.common.dateInterview"/><br>
<myui:calendar title="Max Date of Interview" path="maxDateInterview" bootstrapped="true" placeholder="${messages['common.uTo']}" inputCssClass="form-control" />
</div>
Which renders like this:
I want the message code to remain in the code, but hidden to the user like when you set any label to style="display:none". I don't know how to set this attribute on a spring message tag.
Is there a way to hide a spring message to the user? I don't want the user to see the label "Date of Interview" above the input field.
Spring's message tag doesn't provide attribute you need. All it does is rendering text retrieved from message bundle. If you want to hide it by display:none you should wrap it in some HTML tag and apply hiding style on this outer tag.
It could look like this:
<div class="col-md-3">
<div class="hidden">
<spring:message code="referral.common.dateInterview"/>
</div>
<myui:calendar title="Max Date of Interview" path="maxDateInterview" bootstrapped="true" placeholder="${messages['common.uTo']}" inputCssClass="form-control" />
</div>
CSS:
.hidden {
display: none;
}

Resources