Giter VIP home page Giter VIP logo

Comments (5)

WebReflection avatar WebReflection commented on September 25, 2024

I think what you want there is to use the value, like you'd do with an input:

import {render, html} from 'https://unpkg.com/uhtml?module';

var text = "Hi";

const update = function(e) {
  text = e.currentTarget.value;
  refresh();
  e.preventDefault();
}

const resetText = function() {
  text = '';
  refresh();
}

const refresh = () => {
  render(document.querySelector('#content'), html`
    <h1>${text}</h1>
    <textarea onkeyup=${update} value=${text} />
    <button onclick=${resetText}>Reset</button>
  `);
}

refresh();

this works for me, on keyup/down anything 👋

from uhtml.

Spope avatar Spope commented on September 25, 2024

Ok sure, looks obvious now...
Just to be correct, I'd say you forgot the dot before the value attribute in the snippets.

Thanks for your answer !

from uhtml.

WebReflection avatar WebReflection commented on September 25, 2024

the dot in this case is not necessary, and the guard is different: attributes don't get changed at all if the value is the same (i.e. you just press arrow to move the cursor) while .value=${...} would invoke the setter every single time, which might be a waste of CPU if the browser is not smart about it.

from uhtml.

Spope avatar Spope commented on September 25, 2024

Hum, without the dot, the attribute value is indeed correct but the diplayed content of the textarea is not.
It's empty on first render, and doesn't reset once updated.

from uhtml.

WebReflection avatar WebReflection commented on September 25, 2024

@Spope use the dot then, I probably haven't paid enough attention to this detail, apologies.

from uhtml.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.