Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

skyAutofill directive #157

Merged
merged 9 commits into from
Aug 6, 2020
Merged

skyAutofill directive #157

merged 9 commits into from
Aug 6, 2020

Conversation

Blackbaud-AlexKingman
Copy link
Contributor

blackbaud/skyux-lookup#104

export class SkyAutofillDirective implements OnInit {

/**
* Prevents the browser's native autofill from displaying for an input element.

Choose a reason for hiding this comment

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

Since this property allows "on" or "off", I would suggest changing the wording of the property's description to something like "Enables or disables the browser's native autofill for an input element."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated, but also added similar copy to match the web API's definition for autocomplete: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete.

* @required
*/
@Input()
public set skyAutofill(value: string) {

Choose a reason for hiding this comment

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

It looks like the only valid values are on or off. Should this be a distinct type like we've done elsewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After discussing, we've decided to accepting all strings. I've updated the logic.

}

private setAutocomplete(element: ElementRef, value: string): void {
if (value === 'on') {

Choose a reason for hiding this comment

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

This would be better as a switch statement. Also, what about the case where value is undefined? Should it be the same as on?

switch (value) {
  case 'off':
    break;
  default:
    break;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

this.setAutocomplete(this.elementRef, this._autofill);
}

private setAutocomplete(element: ElementRef, value: string): void {

Choose a reason for hiding this comment

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

Since elementRef and autofill are instance properties, and setAutocomplete() is an instance method, I'd get rid of the parameters and refer to the properties internally to the method. Also, you should only refer to private properties with underscores within a getter or setter; I'd fix this by adding a getter for skyAutofill and referencing it in methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


if (isChrome) {
const name = element.nativeElement.getAttribute('name') || 'sky-input';
this.renderer.setAttribute(element.nativeElement, 'autocomplete', `new-${name}`);

Choose a reason for hiding this comment

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

Instead of duplicating the this.renderer.setAttribute(element.nativeElement, 'autocomplete', x); line, I'd suggest assigning a variable for the attribute value, then calling this.renderer.setAttribute() outside the if statement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

export class SkyBrowserDetector {

public static isChromeDesktop = (
navigator.userAgent.indexOf('Chrome') > -1 &&

Choose a reason for hiding this comment

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

🤮 (though I understand it's necessary)

this.renderer.setAttribute(this.elementRef.nativeElement, 'autocomplete', value);
break;

case undefined || '':

Choose a reason for hiding this comment

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

Is the intent here to fall into this block when this.skyAutofill is either undefined or empty string? The way this is written, it's only going to fall in when it's an empty string, because undefined || '' gets evaluated as ''. If you want both values to fall into the same block, you need to specify two case statements:

case undefined:
case '':
  // Some logic
  break;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops. Forgot switch/case 101 there. Thanks for catching that. Fixed.


<div
class="input-box-visual"
class="input-box-visual sky-padding-even-large"
Copy link
Contributor Author

@Blackbaud-AlexKingman Blackbaud-AlexKingman Aug 6, 2020

Choose a reason for hiding this comment

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

☝️ Prevents the browser's scroll bar from sneaking into the visual tests sometimes.

@codecov
Copy link

codecov bot commented Aug 6, 2020

Codecov Report

Merging #157 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #157   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           29        32    +3     
  Lines          952       889   -63     
  Branches       127       170   +43     
=========================================
- Hits           952       889   -63     
Impacted Files Coverage Δ
.../app/public/modules/autofill/autofill.directive.ts 100.00% <100.00%> (ø)
src/app/public/modules/autofill/autofill.module.ts 100.00% <100.00%> (ø)
...rc/app/public/modules/autofill/browser-detector.ts 100.00% <100.00%> (ø)
src/app/public/modules/radio/radio.module.ts 100.00% <0.00%> (ø)
src/app/public/modules/radio/radio.component.ts 100.00% <0.00%> (ø)
src/app/public/modules/checkbox/checkbox.module.ts 100.00% <0.00%> (ø)
...c/app/public/modules/input-box/input-box.module.ts 100.00% <0.00%> (ø)
.../app/public/modules/checkbox/checkbox.component.ts 100.00% <0.00%> (ø)
.../app/public/modules/radio/radio-group.component.ts 100.00% <0.00%> (ø)
.../app/public/modules/radio/radio-label.component.ts 100.00% <0.00%> (ø)
... and 23 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3ebbf2f...589515e. Read the comment docs.

@blackbaud-ado
Copy link
Member

@Blackbaud-AlexKingman
Copy link
Contributor Author

@Blackbaud-PaulCrowder The changes to the fluid grid in @skyux/layout@4.2.0 were causing the input box visual tests to be wider than normal, hence the mis-match. I deleted all the baselines so they'd be re-created. This should be ready for you again.

@Blackbaud-SteveBrush Blackbaud-SteveBrush merged commit 737730e into master Aug 6, 2020
@Blackbaud-SteveBrush Blackbaud-SteveBrush deleted the sky-auto-fill branch August 6, 2020 19:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants