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

feat: autofill solution #599

Merged
merged 49 commits into from
Jan 25, 2021
Merged

feat: autofill solution #599

merged 49 commits into from
Jan 25, 2021

Conversation

gullerya
Copy link
Contributor

No description provided.

@github-actions
Copy link

🚀

Latest successful build of the PR deployed here.

🚀

@gullerya gullerya marked this pull request as draft January 21, 2021 09:28
Comment on lines 194 to 206
::slotted(input) {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
padding: 0 16px;
box-sizing: border-box;
border-radius: var(--border-radius);
border: none;
background: transparent;
outline: none;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fiddling with input to inset fully results in overlapping icons. this can be alternated by attribute selectors, but I'd suggest leaving this indication to be handled by dedicated overlay element (as in ripple approach)
image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so you suggest to state with the current implementation (I mean the picture you show is not happening in the brach as it is, right)?

@yinonov
Copy link
Contributor

yinonov commented Jan 22, 2021

ran into this trick couple of times 👉 https://github.com/matteobad/detect-autofill/blob/master/src/detect-autofill.js
interesting?

@gullerya
Copy link
Contributor Author

gullerya commented Jan 22, 2021 via email

fe.onblur = this.onInputBlur.bind(this);

// attributes/properties
fe.setAttribute('id', this.id);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this a bit problematic? We're going to have the same ID both on the custom-element as well as on the input.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about this too, while doing that. Concern and my thoughts - sharing to put it here and then up to your take guys:

  • input element having id is somewhat important part of input (for label association, aria label association, sometimes seems to participate in form association and autofill)
  • id should be unique, this is pain
  • to transfer id from parent to child (remove on parent) is no go, since it's intervention into consumer's domain
  • duplicate id IS ugly, no brainer, but not breaking things and seemings won't harm

I'm actually inclined now to remove this and add when absolutely proven needed later.
WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You said that autofill takes id into account - but it also takes name, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, right, so presumable we can stay with name meanwhile. Just see this and pay attention to that wording: user again main require name and/or id attribute.

protected renderInput(): TemplateResult {
this.updateInputElement();
return html`
<div class="mdc-text-field__input"></div>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this for? Is it going to be used by someone?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need it to preserve the effect of that mdc-text-field__input class - spacing, elements positioning around etc.
This is the simplest way to actually preserve all the MWC heavy lifting with that part.

@sonarcloud
Copy link

sonarcloud bot commented Jan 24, 2021

SonarCloud Quality Gate failed.

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
27.4% 27.4% Duplication

@gullerya gullerya marked this pull request as ready for review January 25, 2021 06:12
Comment on lines +152 to +185
fe.onfocus = this.onInputFocus.bind(this);
fe.onblur = this.onInputBlur.bind(this);

// attributes
setAttributeIfDefined('id', this.id, fe);
setAttributeIfDefined('name', this.name, fe);
setAttributeIfDefined('type', this.type, fe);
setAttributeIfDefined('form', this.form, fe);
setAttributeIfDefined('placeholder', this.placeholder, fe);

setAttributeIfDefined('min', this.min, fe);
setAttributeIfDefined('max', this.max, fe);
setAttributeIfDefined('step', this.step, fe);
setAttributeIfDefined('size', this.size, fe);

const autoCapOrNone = this.autocapitalize ? this.autocapitalize : undefined;
const minOrNone = this.minLength === -1 ? undefined : this.minLength;
const maxOrNone = this.maxLength === -1 ? undefined : this.maxLength;
setAttributeIfDefined('autocapitalize', autoCapOrNone, fe);
setAttributeIfDefined('minlength', minOrNone, fe);
setAttributeIfDefined('maxlength', maxOrNone, fe);
setAttributeIfDefined('pattern', this.pattern, fe);
setAttributeIfDefined('inputmode', this.inputMode, fe);

addAttributeByCondition('disabled', this.disabled, fe);
addAttributeByCondition('readonly', this.readOnly, fe);
addAttributeByCondition('required', this.required, fe);

const ariaLabel = shouldRenderHelperText ? 'helper-text' : undefined;
const ariaError =
this.validationMessage && !this.isUiValid ? 'helper-text' : undefined;
setAttributeIfDefined('aria-controls', ariaLabel, fe);
setAttributeIfDefined('aria-describedby', ariaLabel, fe);
setAttributeIfDefined('aria-errortext', ariaError, fe);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouchs ;)

const [formElement] = addElement(
createElementInForm(fieldName, fieldValue)
);
const [formElement] = createElementInForm(fieldName, fieldValue);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const [formElement] = createElementInForm(fieldName, fieldValue);
const [formElement] = addElement(createElementInForm(fieldName, fieldValue));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

applied

YonatanKra
YonatanKra previously approved these changes Jan 25, 2021
Copy link
Contributor

@YonatanKra YonatanKra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I'll push one small change

@sonarcloud
Copy link

sonarcloud bot commented Jan 25, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@yinonov yinonov merged commit 284a5f0 into master Jan 25, 2021
@gullerya gullerya deleted the autofill-solution branch January 25, 2021 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants