lit.dev | The Lit website | Web Site library
kandi X-RAY | lit.dev Summary
kandi X-RAY | lit.dev Summary
New site, new repo.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of lit.dev
lit.dev Key Features
lit.dev Examples and Code Snippets
Community Discussions
Trending Discussions on lit.dev
QUESTION
Lit docs refer to Web Test Runner as testing. It navigates to this example page.
I tried testing MyElement
, which has only one
.
...ANSWER
Answered 2022-Jan-31 at 14:08Try shadowRoot instead of shadowDom:
QUESTION
I want to compose a LitElement widget from two other widgets. The basic idea would be that one "selector" widget selects something, send an event to its parent "mediator" one, which in turns would update the related property in a "viewer" child widget (event up, property down). This follows the "mediator pattern" example of the documentation about composition, only that I need to deal with fully separated classes.
Below is a minimum working example, which builds and run in the LitElement TypeScript starter template project, with all dependencies force-updated with ncu --upgradeAll
.
The desired behavior would be that the Viewer widget does render the item["name"]
when the user selects something in the dropdown list.
So far, I managed to send an event up from the Selector to the Mediator, and to update the item_id
attribute within the Viewer. However, this does not seem to trigger an update of the item_id
property of the Viewer.
The approach used is to override updated
in the Mediator (l.36), loop through its children and do a child.setAttribute
, which is probably highly inelegant. There is surely another —cleaner— way, but I failed to clearly understand the update sequence of Lit.
ANSWER
Answered 2022-Mar-31 at 09:48You are setting the item only in the connectedCallback. Better you get the item dynamically via getter.
Regarding your question of setting an attribute of a slotted element, there is in my opinion no other way than programmatically.
QUESTION
I have a really simple template and a simple nested template. Unfortunately, my nested template doesn't render anything.
I followed the example defined at: https://lit.dev/docs/components/rendering/
This is my container template.
...ANSWER
Answered 2022-Mar-07 at 13:12Anytime we implement lifecycle callback methods, it's necessary to call the parent class's methods (so the superclass features work as-expected).
If you need to customize any of the standard custom element lifecycle methods, make sure to call the super implementation (such as super.connectedCallback()) so the standard Lit functionality is maintained.
QUESTION
This is really odd: I'm using lit
in a storybook (using @storybook/html
).
I do not know why, but in my environment lit
does not update the component automatically when a property has been changed. If I call requestUpdate
explicitly, it is indeed updating.
This happens with every component, even this very simple demo component (shows 'waiting...' first, and after 3 seconds it should show 'done') ... working obviously in this codesandbox ... but not working in my storybook :-(
https://codesandbox.io/s/weathered-river-087wz?file=/src/index.ts
Is there by any change anybody who might have an idea what could be the reason for this strange issue? TYVMIA
[EDIT]: This might be the reason:
https://lit.dev/msg/class-field-shadowing
You should use "useDefineForClassFields": false
in tsconfig.json.
Actually I indeed had set it to true
, but after changing to false
I still have the above issue.
PS: I'm using the latest versions of lit (2.1.1) and storybook (6.4.13)
PPS: Removing directory node_modules
and file yarn.lock
and running yarn install
did not solve the problem
ANSWER
Answered 2022-Jan-30 at 18:03In tsconfig.json
you have to set option useDefineForClassFields
to false
to make lit
run properly. For more information please see
https://lit.dev/msg/class-field-shadowing .
To fully solve the issue with Storybook/Webpack I also had to do the following:
yarn add -D ts-loader@8.3.0
(version 9.x does not work with Webpack4)[EDIT: Please check Vince's answer below ... his solution (= main.js + webpackFinal) seems to be the preferred way]
Adding the following to
.storybook/webpack.config.json
(not really sure why):
QUESTION
I'm currently diving into Webcomponents with Litelements: In Webcomponents you can change the way the shadowdom works by defining the mode property as 'open' or 'closed'. Like this in vanilla Javascript without LitElements:
Javascript:
...ANSWER
Answered 2022-Jan-20 at 13:08By default lit element is acting in mode open
.
So customLitElement.shadowRoot
returns a shadow-root.
If you want to run it in closed mode implement this method:
QUESTION
I'm trying to create a simple proof-of-concept of using Deno to bundle a browser application which is using Lit. Basic functionality (e.g., initial component rendering) is functional, but I'm unable to get simple DOM manipulations to trigger the reactive property changes.
My simple example can be seen working at this Lit Playground example. An example which does not work is this Deno bundle version. These 2 versions have the exact same source code (i.e., index.html
and main.ts
).
You can view all of the code and the build process for creating the Deno bundle here.
Is Deno capable of producing bundles which behave in the expected manner?
...ANSWER
Answered 2022-Jan-11 at 16:45Deno 1.17.2 is able to successfully create a bundle. See https://github.com/denoland/deno/issues/13048 for background. As @jsejcksn said, SWC is most likely the culprit for the original issue.
QUESTION
lit introduces an example of "Change detection" at the following URL. https://lit.dev/playground/#sample=examples/properties-has-changed
Why is there a "." at the beginning of "date" when specifying the "date-display" option in line 16 of my-element.ts?
...ANSWER
Answered 2021-Jun-23 at 08:13Lit uses prefixes to indicate the type of expression in a component's template. The .
prefix denotes a property expression; without the prefix it would be an attribute expression. Using a property expression makes it very easy and convenient to pass any JS object to a child element (in this case a Date
object).
When using HTML attributes you need to be aware that they are always strings. JS data must be converted to a string on the parent element, and then possibly converted back to the corresponding JS type on the child element. No such conversion is performed with property expressions, because the data stays in "JS land".
So, why not always use property expressions? Two examples come to my mind right away:
For a property expression to work you need to know an implementation detail of the child element, i.e. that it has a corresponding JS property. (If you're dealing with your own Lit based elements inside a single project that is not a problem.)
If you want to apply selectors based on attributes (e.g. for styling
my-button[disabled] { /* CSS ... /* }
or using querySelector).
QUESTION
If I look at the polymer shop I am instantly sold on wanting to use this as a starter for my web shop. Not just because it's already a web shop (full pwa technology) but because it has excellent (offline) experience on browser/mobile, has proper documentation and is still maintained.
But then look at the polymer home page and see the project is based on an outdated polymer version and even the fact that it's using polymer in the first place is curious:
The Polymer library is in maintenance mode. For new development, we recommend Lit.
So my question is if lit will have the rich choice of web components that the shop seems to be depending on?
This may be a dumb question but I skipped polymer other than looking at some exciting news in google IO
...ANSWER
Answered 2021-May-17 at 17:18The goal of Lit, and of Polymer before it, is to help build web components and applications using browser features as much as possible.
For instance jQuery wrapped all the different browser features in it's own syntax, to the point where developers were learning jQuery, rather than Javascript. jQuery components assume that you have jQuery and rely on those jQuery methods to function.
Both Lit and Polymer championed web components - this makes each component much more self-contained. Using a mix of jQuery and any of its competitors was really painful, but that isn't the case here.
All the components used to build that shop are stable and still on npm. You can use them if you want and I have live applications that still use them.
However, championing the latest browser features has its risks. Polymer relied heavily on HTML Imports (that only Chrome ever implemented and were ultimately dropped) and its own template library. It was ultimately ported to ES6 modules, but the core design is far less suited to it. Those components are pretty stable, but you don't really want to start anything new with it.
Lit is quite a lot less opinionated than Polymer, and much lower level. For instance Polymer supported two way binding with {{property}}
syntax, but had to make assumptions (that often broke) about what you were doing to support it. Lit drops that for extremely stable property setters but if you want to users to write values you have to subscribe to events and roll that yourself (Lit does make events very easy to manage though).
So if you're going to build your own web components or application Lit is by far the better choice, and LitElement is lightweight and extremely compatible with everything else. You can use those Polymer shop components in Lit (I have) but for most of them there are newer alternatives, in particular MWC.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install lit.dev
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page