Why is ::part() not working for slotted Stencil elements? - pseudo-element

My HTML:
<my-dropdown label="dropdown" size="m" filter="true">
<select slot="filter" part="myselect">
<option>One</option>
<option>Two</option>
<option>Three</option>
</select>
</my-dropdown>
Inside the my-dropdown components, I have a slot:
<slot name="filter" />
The css stylesheet is inside the component, and in it, I have defined:
my-dropdown::part(myselect) {
..
}
The styles do not apply to the component! Why? Am I not doing it correctly?

Simple answer: Because it's not meant to work on slotted elements.
The CSS parts ::part() pseudo-element selector is used to apply style to elements that are within shadow DOM which use the part attribute.
In your example, you have added the part attribute to the element <select slot="filter" part="myselect"> which is in light DOM not shadow DOM.
Note that slotted elements are not actually moved to the shadow DOM; their position in the DOM is not affected by the slotting mechanism so they exist in regular light DOM like any other element. They are just rendered inside the shadow DOM structure of the parent web component, with both the component's shadow DOM style for that slot (::slotted()) and any regular DOM styling e.g. global stylesheet applied.
In order for the my-dropdown::part(myselect) selector to work, the element that has the part="myselect" attribute would have to be inside the shadow of the my-dropdown component - for example:
#Component({
tag: 'my-dropdown',
styleUrl: 'my-dropdown.scss',
shadow: true,
})
export class MyDropdown {
render() {
return (
<Host>
<div part="myselect">
<slot name="filter" />
</div>
</Host>
);
}
}

Related

how to references rulenames in a child component in jss

I'm using Material-UI. As it supports CSS styling with JSS, I'm struggling to access rule names in a different component. As you see the below codes, MyComponent uses AppBar component and I need to access rule names in AppBar component. However, for some reason I can't access the rule names in it.
MyComponent.js
<div id="navigation-pills">
<div className={classes.root}>
<AppBar position="static" color="default">
<Tabs
...
>
...
</Tabs>
</AppBar>
</div>
</div>
styles.js
const styles = theme => ({
...
root: {
flexGrow: 1,
width: "100%",
backgroundColor: theme.palette.background.paper,
"& $flexContainer": {
display: "none"
}
},
...
});
JSS API says that I can access child rule names with $, but it doesn't work for some reason.
L
Like you see the below image, I would like to access flexContainer rule name on line 7.
It can only reference a rule from the same style sheet (styles object). In your code I can't tell, because you replaced it with "...".

Wicket CheckBoxMultipleChoice

How to change css style of Rendered html of CheckBoxMultipleChoice? CheckBoxMultipleChoice renders this html output by default but i want to change css style of this rendered output
<div class="ca-info__cat-roles js-roles-1 expanded" wicket:id="categories" id="categoriesb">
<input name="categories" type="checkbox" value="819" id="categoriesb categories_819">
<label for="categoriesb-categories_819">index>root>CategoryCatalog.png>9</label>
<input name="categories" type="checkbox" value="829" id="categoriesb-categories_829">
<label for="categoriesb-categories_829">index>root>tv.png>9</label>
</div>
I want to change styles of inputs and labels, but i don't know how to do it with CheckBoxMultipleChoice.
I have done this way. There are two ways
Add CSS in html page itself . inside style tag add your style like below but this will affect other component if you have same style.
.ca-info__cat-roles js-roles-1.expanded label{
// Your style for label
}
.ca-info__cat-roles js-roles-1.expanded input{
// Your style for input
}
2.Another way You can override#appendHtml and derive your own style for check box (e.g)buffer.append("class=\"yourStyleclass\"");.
In addition to use custom css for you component you have to use setSuffix() and setPrefix() methods, like this:
checkboxes = new CheckBoxMultipleChoice<>("checkboxes", value);
checkboxes.setSuffix("<br/>");

Change border color of required Chosen jQuery select boxes

Simply put, how can you change the border color of a Chosen jQuery select box? I am assuming you can do it with CSS but I can't quite figure out how.
$(".pnChosen").chosen({
search_contains: true
});
<select required class="pnChosen"></select>
I can use this to change the border color of all of them, but I only want to change ones that I mark as required.
.chosen-container{
border: 1px solid red;
}
And I also want to change the background color when they are disabled if that is possible.
You can use chosen's option inherit_select_classes.
Give required class on select element, and set css for this selector .required>chosen-single
$(".pnChosen").chosen({
search_contains: true,
inherit_select_classes: true
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.4.2/chosen.jquery.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.4.2/chosen.css" rel="stylesheet" />
<style>
.required>.chosen-single {
border: 1px solid #EE0000;
}
</style>
<select required class="pnChosen required">
<option>Option 1</option>
<option>Option 2</option>
</select>
Another option is to use the adjacent sibling combinator (+) selector in CSS to achieve the desired styling.
For example:
HTML
<select id="myselect" required="required">
...
</select>
<div id="myselect_chosen" class="chosen-container chosen-container-single">
<a class="chosen-single">
...
</a>
</div>
CSS
select:required + div.chosen-container a { ... }
This would apply the desired style(s) to your div.chosen-container a DOM element immediately following select:required. Just be aware that you may still have to establish CSS priority if you're attempting to override an existing Chosen style so your definitions can supersede any existing chosen styles.
Reference: Adjacent Sibling Combinator

Fancy Tree Dropping externals HTML on fancy tree node

I am facing a problem while dragging the elements from different iframe to the fancy TREE node?
function test(){
$("#tetsingDIV1").draggable({ revert: true, cursor: "move", cursorAt: { top: -5, left: -5 }, connectToFancytree: true });
}
HTML part
<body onload="test()">
<a id="tetsingDIV1" style="cursor:move;text-decoration: none !important;" href="_param=dfasdfdsadasdasdasdasdasdas"> <img src='../common/images/iconDragDrop.png'</a> </body>
I want to drag the above HTML element on the fancy tree node
Any solution for this? I have tried this: ON the external iframe for a DIV; I have added draggable event too.so that fancytree can accept it.

Swipe.js callback function

I'm using swipejs (https://github.com/bradbirdsall/Swipe) and want to add a class to certain DOM elements if the slide being slided to has a data attribute.
In this case a slide may have the attribute of data-colour="orange". When sliding to that slide I want to addClass '.orange' to any DOM element that hasClass '.colour'
HTML:
<!-- Slide 1 -->
<div class="slide" data-colour="orange">
<h1 class="center">we know sport</h1>
</div>
<!-- Slide 2 -->
<div class="slide" data-colour="blue">
<h1 class="center">we really know football</h1>
</div>
jQuery:
$(document).ready(function(){
var elem = document.getElementById('mySwipe');
window.mySwipe = Swipe(elem, {
callback: function(){
colour.addClass($('.slide').data('colour'));
}
});
});
This performs the desired action, but will only apply the data attribute of the current slide when sliding to the next slide, whereas I would like to work out the data attribute of the next slide, and when sliding to it add that as a class to other DOM elements.
Any help would be greatly appreciated.
Swipe 2.0 adds attribute data-index, so you could write:
$('#mySwipe [data-index='+(mySwipe.getPos()+1)+']').data('colour')