Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calcite-input: pass through native input attributes #4079

Closed
noahmulfinger opened this issue Feb 8, 2022 · 7 comments
Closed

calcite-input: pass through native input attributes #4079

noahmulfinger opened this issue Feb 8, 2022 · 7 comments
Assignees
Labels
4 - verified Issues that have been released and confirmed resolved. enhancement Issues tied to a new feature or request.

Comments

@noahmulfinger
Copy link
Contributor

noahmulfinger commented Feb 8, 2022

Repurposing this issue to add all of the native input attributes that should be passed through.

Description

The accept attribute restricts the type of files that can be selected when an input has the type file. It would be useful to have this attribute available on calcite-input.

Acceptance Criteria

The accept property is passed down from the calcite-input into the internal input.

Relevant Info

MDN docs for this attribute: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/accept

Which Component

calcite-input

Example Use Case

Profile image upload:

<calcite-label>
  Upload profile image (must be png or jpg)
  <calcite-input type="file" accept="image/png, image/jpeg"></calcite-input>
</calcite-label>
@noahmulfinger noahmulfinger added enhancement Issues tied to a new feature or request. 0 - new New issues that need assignment. needs triage Planning workflow - pending design/dev review. labels Feb 8, 2022
@benelan benelan changed the title calcite-input: Add support for "accept" attribute when type="file" calcite-input: pass through native input attributes Apr 29, 2022
@benelan
Copy link
Member

benelan commented Apr 29, 2022

@macandcheese @jcfranco can we triage this to the next sprint?

@benelan benelan added 1 - assigned Issues that are assigned to a sprint and a team member. and removed 0 - new New issues that need assignment. needs triage Planning workflow - pending design/dev review. labels Apr 29, 2022
@benelan benelan self-assigned this Apr 29, 2022
@benelan benelan added this to the Sprint 05/09 - 05/20 milestone Apr 29, 2022
@benelan benelan added the 2 - in development Issues that are actively being worked on. label Nov 23, 2022
benelan added a commit that referenced this issue Nov 28, 2022
…ccept, multiple, pattern (#5807)

**Related Issue:** #4079 

## Summary
Adds native input attributes:

-
[multiple](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/multiple)
to `calcite-input` for the types specified on MDN
-
[accept](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/accept)
to `calcite-input` for the types specified on MDN
-
[pattern](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/pattern)
to `calcite-input-text` and `calcite-input` for the types specified on
MDN
-
[autocomplete](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete)
to `calcite-input-number`, `calcite-input-text`, and `calcite-input` for
the types specified on MDN

## Note
just saw on MDN after committing that Safari may not support
`autocomplete`:

https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete#browser_compatibility

Should I remove it from the PR?


<!--
Please make sure the PR title and/or commit message adheres to the
https://www.conventionalcommits.org/en/v1.0.0/ specification.

Note: If your PR only has one commit and it is NOT semantic, you will
need to either

a. add another commit and wait for the check to update
b. proceed to squash merge, but make sure the commit message is the same
as the title.

This is because of the way GitHub handles single-commit squash merges
(see zeke/semantic-pull-requests#17)

If this is component-related, please verify that:

- [ ] feature or fix has a corresponding test
- [ ] changes have been tested with demo page in Edge

---

If this is skipping an unstable test:

- include info about the test failure
- submit an unstable-test issue by
[choosing](https://github.com/Esri/calcite-components/issues/new/choose)
the unstable test template and filling it out

-->
@benelan benelan added 3 - installed Issues that have been merged to master branch and are ready for final confirmation. and removed 1 - assigned Issues that are assigned to a sprint and a team member. 2 - in development Issues that are actively being worked on. labels Nov 28, 2022
@github-actions
Copy link
Contributor

Installed and assigned for verification.

@benelan benelan removed their assignment Nov 29, 2022
@geospatialem
Copy link
Member

Verified accept and multiple props. ✔️

@benelan Seeking your expertise 🧠 for verifying the autocomplete and pattern props are coming in as-expected with the following Codepen, where:

  1. autocomplete:
    Unable to reproduce similar behavior to the native input where information is populated, such as email address.

  2. pattern:
    Unable to discern how to use the new prop similar to the native input without using JavaScript to interpret.

@benelan
Copy link
Member

benelan commented Dec 1, 2022

My understanding is we have a post v1 epic to improve form validation, and for now users will still need JS like you mentioned. Here's an example:
https://codepen.io/benesri/pen/xxzaNKW?editors=1010

cc @driskull in case I'm wrong about that. I can another stab at it if so.

For autocomplete you have to have it turned on in your browser and have saved info. This works for me:
https://codepen.io/benesri/pen/LYrJozq?editors=1010

image

@geospatialem geospatialem added 4 - verified Issues that have been released and confirmed resolved. and removed 3 - installed Issues that have been merged to master branch and are ready for final confirmation. labels Dec 1, 2022
@geospatialem
Copy link
Member

geospatialem commented Dec 1, 2022

Awesome, thanks for your expertise! Was missing the name attribute for autocomplete.

Everything looks great in next.649 in the following Codepen.🎇

Marking as verified, since form validation will come later (and as long as JS is expected for pattern at this time). Will re-open if anything changes.

accept:

<calcite-label>Accept png sample
  <calcite-input type="file" accept="image/png"></calcite-input>
</calcite-label>

autocomplete:

<calcite-label layout="inline">Autocomplete email sample
  <calcite-input name="email-input" type="email" autocomplete="email"></calcite-input>
</calcite-label>

multiple:

<calcite-label>Multiple files sample
  <calcite-input type="file" multiple></calcite-input>
</calcite-label>

pattern:

html

<form name="myForm">
  <calcite-label id="username-label" for="username">Username
    <calcite-input type="text" id="username-input" name="username-input" required pattern="[a-z]{4,8}" title="4 to 8 lowercase letters">
    </calcite-input>
    <calcite-input-message hidden icon id="username-message">
        Usernames must be lowercase and 4-8 characters in length.
    </calcite-input-message>
  </calcite-label>
  <calcite-button id="submit-button" name="submit" label="submit">
    Submit
   </calcite-button>
</form>

js

const input = document.getElementById("username-input");
const button = document.getElementById("submit-button");
document.getElementById("submit-button").addEventListener("click", (event) => {
  if (new RegExp(input.pattern).test(input.value)) {
    alert("form submitted");
    document.myForm.submit();
  } else {
    const info = document.getElementById("username-message");
    input.status = "invalid";
    info.status = "invalid";
    info.hidden = false;
  }
});

@yelenakreyndel
Copy link

@macandcheese why do we have this issue listed on confluence in the Next section here: https://confluencewikidev.esri.com/display/Calcite/New+Web+Components

@macandcheese
Copy link
Contributor

@yelenakreyndel opened a new issue for tracking, will update Confluence: #6545

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4 - verified Issues that have been released and confirmed resolved. enhancement Issues tied to a new feature or request.
Projects
None yet
Development

No branches or pull requests

5 participants