Giter Club home page Giter Club logo

form-participation's Introduction

Open-wc Logo

Open Web Component Recommendations

Open Web Components provides a set of defaults, recommendations and tools to help facilitate your web component project. Our recommendations include: developing, linting, testing, building, tooling, demoing, publishing and automating.

Usage

# in a new or existing folder:
npm init @open-wc
# requires node 10 & npm 6 or higher

This will kickstart a menu guiding you through all available actions.

$ npm init @open-wc
npx: installed 30 in 1.762s

        _.,,,,,,,,,._
     .d''           ``b.       Open Web Components Recommendations
   .p'      Open       `q.
 .d'    Web Components  `b.    Start or upgrade your web component project with
 .d'                     `b.   ease. All our recommendations at your fingertips.
 ::   .................   ::
 `p.                     .q'   See more details at https://open-wc.org/init/
  `p.    open-wc.org    .q'
   `b.     @openWc     .d'
     `q..            ..,'      Note: you can exit any time with Ctrl+C or Esc
        '',,,,,,,,,,''


? What would you like to do today? › - Use arrow-keys. Return to submit.
❯   Scaffold a new project
    Upgrade an existing project

Homepage

For more details please visit us at open-wc.org.

Packages

Package Version Description
building-rollup building-rollup Default configuration for working with rollup.
create create Scaffold web components following open-wc recommendations.
demoing-storybook demoing-storybook Storybook configuration following open-wc recommendations.
eslint-config eslint-config Eslint configuration following open-wc recommendations.
es-dev-server es-dev-server Development server for modern web apps.
polyfills-loader polyfills-loader Load web component polyfills using dynamic imports.
scoped-elements scoped-elements Auto define custom elements to scope them and avoid the name collision.
semantic-dom-diff semantic-dom-diff To compare dom and shadow dom trees. Part of open-wc recommendations.
testing testing Testing following open-wc recommendations.
testing-helpers testing-helpers Testing Helpers following open-wc recommendations.
testing-karma testing-karma Testing with Karma following open-wc recommendations.
testing-karma-bs testing-karma-bs Testing with Karma using Browserstack following open-wc recommendations.
testing-wallaby testing-wallaby Testing with wallaby following open-wc recommendations.

Contact

Feel free to reach out to us on 𝕏 (Twitter) or create a github issue for any feedback or questions you might have.

You can also find us on the Lit & Friends slack in the #open-wc channel.

You can join the Lit & Friends slack by visiting https://lit.dev/slack-invite/.

Sponsored by

Chrome's Web Framework & Tools Performance Fund Logo Divriots Logo

Supported by

Browserstack Logo netlify logo

Guide

# bootstrap/setup
npm install

# linting
npm run lint

# local testing
npm run test

# testing via browserstack
npm run test:bs

# run commands only for a specific scope
lerna run <command> --scope @open-wc/<package-name> --stream

form-participation's People

Contributors

bennypowers avatar calebdwilliams avatar davestein avatar michaelwarren1106 avatar muratcorlu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

form-participation's Issues

Generated events require "bubbles" prop for event delegation

Looks like starting in React 17 generated events require the bubbles prop to be set for proper handling.

https://reactjs.org/blog/2020/08/10/react-v17-rc.html#changes-to-event-delegation
Reference discovered in this stack post https://stackoverflow.com/questions/51026510/react-ref-form-onsubmit-handler-not-triggered/66659749#66659749

I came across this while investigating issues I was having with form submission event handling when triggered by child web components with in the shadow dom.

Setting the 'bubbles' prop on the event solved the issue and allowed for proper event handling by react triggering form control and expected onsubmit behavior.

Adding this to

const submitEvent = new Event('submit', {
should improve compatibility.

`@open-wc/form-control` package not published as ESM module

All of the other @open-wc packages we leverage are published with the "type": "module" package.json configuration. Is there any reason why @open-wc/form-control specifically is not considering @open-wc/form-helpers is? It has just caused some strange build errors that might prevent us from leveraging it.

TypeError: this.attachInternals is not a function

I'm trying to use my components with Lit SSR, but the ones using FormControlMixin cause this error:

TypeError: this.attachInternals is not a function

Is there anything I could do to prevent this?

Validator attribute required?

One of my devs got an error today about an attribute property not existing on a validator object.

The error came from this line:
https://github.com/open-wc/form-participation/blob/main/packages/form-control/src/FormControlMixin.ts#L39

Which seems to be coded as if the attribute key in the validator object is required, but its typed as optional in the TS typing. IMO it should be optional, so should we do an existence check on the .attribute prop in that map function?

Async custom validators

As far as I see currently we are not able to set custom async validators. Do you have a design decision to stick to sync validators or is it just ok for adding async support with a PR?

Catching form submit and showing validation errors

I'm using this library to build a form that consist on a custom input and a custom submit button. Submit button uses submit helper from form-helpers. I expect that submitting form directly without making any change should trigger form validation, block form submit and show error messages. But;

  1. If there is a validation error in the form (like a required field) submit helper doesn't call submit. It only calls reportValidity of form. But as far as I see, form's reportValidity doesn't call our custom inputs' reportValidity methods. So form submission is being blocked but no errors shown.
  2. I'm trying to catch submit event of the wrapping form in my custom input to call its own reportValidity method but since submit event doesn't happen with submit helper, it doesn't help as well. (This works with native <button type="submit">)
  3. Validators doesn't run when we don't set a value, so validityCallback is not called if there is no use interaction (like initial state). I have an input like <my-input required> and if user immediately submits the form, required validator of the component doesn't work. Because validityCallback doesn't work, I can not override default error message in this case.

It would be great to have a comprehensive form example that has custom input and custom form submit button both uses this library and shows default or custom error messages once form is submitted.

I tried to demonstrate the issue but couldn't manage it easily in a playground (setup needs some considerable time). But if it's difficult to understand the issues I explained, I can spend more time to show an example.

Not associating with form in React?

We're having issues in React. Controls seem to get associated fine outside of React, but within a React app the control never seems to get associated with the form?

The internals seem to recognize the form and everything works like normal, but the FormData pulled from the form in React doesn't properly contain the web component control's name and value?

Curious if anyone else has run into this? I'll try to get an example recreation online soon.

Uncaught (in promise) Error using classfield with a new vite lit-ts project

Reproducing

When I set up a new vite project using the lit-ts template, and using this component while installing @open-wc/form-control I am getting the following error.

🐛 Reproduced Error Demo

Error

Uncaught (in promise) Error: The following properties on element fd-input will not trigger updates as expected because they are set using class fields: value. Native class fields and some compiled output will overwrite accessors used for detecting changes. See https://lit.dev/msg/class-field-shadowing for more information.
    at Input.performUpdate (reactive-element.ts:1275:17)
    at Input.scheduleUpdate (reactive-element.ts:1234:17)
    at Input.__enqueueUpdate (reactive-element.ts:1206:25)

Expected Behavior

The component works just fine as it does in this Demo

Actual Behavior

The app is just showing nothing instead and throws the above mentioned error
Screenshot 2022-03-08 at 22 50 22

Change setValue method in FormControlMixin to limit TS visibility

Problem

The FormControlMixin currently exposes the setValue method as a public method on elements that use the mixin. When using the FormControlMixin to build a published component for other teams to use, this can lead to confusion when consuming teams use TypeScript. Since setValue is public it appears as though it is intended for direct use by said consuming teams.

Impact

This misunderstanding may cause improper usage patterns and bypasses the intended abstractions we've designed for managing state and interactions within form control elements.

Proposed Solution

Changing setValue from a public method to a protected method would be ideal on our end. However, I understand this might not be ideal on your end. We're open to other potential solutions as well.

Form submission element is absent from `event.submitter`

When I submit a <form/>, I'd like to know which element submitted the form.
In native HTML, I have access to the element that submitted the form via event.submitter

Read more about the event.submitter spec here

Example:

// JS
document
    .querySelector("form")
    .addEventListener("submit", (event) => {
        let submitter = event.submitter;
    });

// HTML
<form>
    <button name='FirstButton' value='FirstValue'>First</button>
    <button name='SecondButton' value='SecondValue'>Second</button>
</form>

Expected:
event.submitter should be a reference to the DOM node

Received:
event.submitter is null

FormControlMixin causes build failures on server/Lit SSR

The calls to addEventListeners in the element's constructor break Lit SSR compatibility.

Could these be moved to the connectedCallback?

connectedCallback() {
  super.connectedCallback();

  this.addEventListener?.('focus', this.#onFocus);
  this.addEventListener?.('blur', this.#onBlur);
  this.addEventListener?.('invalid', this.#onInvalid);
}

Alternatively, perhaps provide a method we can override to inform the mixin if it is being rendered on a server at the moment but in a library agnostic way:

protected isServer() {
  return false;
}

constructor(...args: any[]) {
  super(...args);

  if (!this.isServer()) {
    this.addEventListener?.('focus', this.#onFocus);
    this.addEventListener?.('blur', this.#onBlur);
    this.addEventListener?.('invalid', this.#onInvalid);
  }
  this.setValue(null);
}

So then in a Lit element we could just override:

import {isServer} from 'lit';

// ...

  protected isServer() {
    return isServer;
  }

formControlValidationGroup implementation missing

i saw a example using formControlValidationGroup
now i checked the code and the history on formControlValidationGroup there was a pr from @calebdwilliams
but i dont think there is any current implementation using formControlValidationGroup was this intentionaly?

is there a work around for this so you can validate radio input groups?
if not ill see if i can help with a implemention to put it back in

it use to be added with this pr #12

i also see formValidationGroup still in there

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.