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

fix(button): add disable button behavior #76

Merged
merged 4 commits into from
Jun 9, 2017

Conversation

chrsmrtn-
Copy link
Contributor

this adds in disabled behavior when defined for <ux-button></ux-button>

resolves #75

@CLAassistant
Copy link

CLAassistant commented Jun 5, 2017

CLA assistant check
All committers have signed the CLA.

@serifine serifine changed the title bug(button): add disable button behavior fix(button): add disable button behavior Jun 6, 2017
@@ -12,7 +12,7 @@ export class UxButton implements Themable {
@bindable public type = null;
@bindable public size = null;
@bindable public effect = null;
@bindable public disabled = false;
@bindable public disabled: any = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't this be @bindable public disabled: boolean | string = false?

Copy link
Contributor

Choose a reason for hiding this comment

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

@ZHollingshead Let's definitely use the typings mentinoed by @RichiCoder1

Copy link
Contributor

Choose a reason for hiding this comment

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

I like this a lot.

@@ -29,12 +29,24 @@ export class UxButton implements Themable {
if (this.theme) {
this.styleEngine.applyTheme(this, this.theme);
}

if (this.disabled || this.disabled === '') {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious what the reasoning is behind this line? It seems contradictory.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's to treat empty strings as true? It is confusing. @ZHollingshead If we switch to the more explicit typing above we can probably write some clearer logic here as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

We should be able to check directly against false or empty with stricter types.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ZHollingshead, hey wanted to run this possible change past ya and get feedback. I've casted the disabled variable per @RichiCoder1's suggestion:

   @bindable public disabled: boolean | string = false;

Now I'm working on the subsequent if block to clear that logic up a bit. Specifically, I wanted to highlight that we are attempting to detect an empty string as true. All other casting from string to boolean will behave as normal. As well as all other castings to boolean will behave as normal.

    // ensure we cast empty string as true
    if (typeof this.disabled === 'string' && this.disabled === '') {
      this.disabled = true;
    }

    if (this.disabled) {
      this.button.setAttribute('disabled', '');
    }

Also wondering if we should be using this.button.setAttribute('disabled', 'true'); instead like we've done in the disabledChanged hander?

Copy link
Contributor

Choose a reason for hiding this comment

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

That logic makes much more sense now. Is there a meaningful difference in browser between disabled="" and disabled="true"? If not, I'd opt for the former in both places.

Copy link
Contributor Author

@chrsmrtn- chrsmrtn- Jun 6, 2017

Choose a reason for hiding this comment

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

Here's what I've found. It seems that disabled="true" will result to false. This stackoverflow answer references the HTML 5 spec:

https://stackoverflow.com/questions/6961526/correct-value-for-disabled-attribute

I'm almost thinking now that the original intention of that snip of code was to follow the HTML 5 spec. I took my original code from the ux-input.ts source to stay consistent within the project.

@EisenbergEffect @ZHollingshead, does the above sound right when ux-input was written out?

After we finalize this behavior and coding for the ux-button, i'll make another pull request to move these changes into other components that use the disabled and readonly attributes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh, yes, that's the correct SO I was looking for. Boolean attributes in HTML are a bit weird about that. I'd def do setAttibute(attributeName, '') or all instances of disabled and readonly. I don't think Aurelia is too concerned with XHTML compatibility.

Copy link
Contributor

Choose a reason for hiding this comment

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

@chrsmrtn- setAttribute('disabled', '') is the way to go in my opinion.

@@ -12,7 +12,7 @@ export class UxButton implements Themable {
@bindable public type = null;
@bindable public size = null;
@bindable public effect = null;
@bindable public disabled = false;
@bindable public disabled: any = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

@ZHollingshead Let's definitely use the typings mentinoed by @RichiCoder1

@@ -29,12 +29,24 @@ export class UxButton implements Themable {
if (this.theme) {
this.styleEngine.applyTheme(this, this.theme);
}

if (this.disabled || this.disabled === '') {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's to treat empty strings as true? It is confusing. @ZHollingshead If we switch to the more explicit typing above we can probably write some clearer logic here as well.

@@ -12,7 +12,7 @@ export class UxButton implements Themable {
@bindable public type = null;
@bindable public size = null;
@bindable public effect = null;
@bindable public disabled = false;
@bindable public disabled: any = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's go ahead and change this as mentioned above.

@@ -29,12 +29,24 @@ export class UxButton implements Themable {
if (this.theme) {
this.styleEngine.applyTheme(this, this.theme);
}

if (this.disabled || this.disabled === '') {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should be able to check directly against false or empty with stricter types.

}

public themeChanged(newValue: any) {
this.styleEngine.applyTheme(this, newValue);
}

public disabledChanged(newValue: any) {
Copy link
Contributor Author

@chrsmrtn- chrsmrtn- Jun 6, 2017

Choose a reason for hiding this comment

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

Should we also adjust this casting to match what we've done for the disabled attribute? So this would now become:
public disabledChanged(newValue: boolean | string) {?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yup! Though in this case it'd be boolean | string | null as I believe an end user could technically null it out.

Copy link
Contributor Author

@chrsmrtn- chrsmrtn- Jun 7, 2017

Choose a reason for hiding this comment

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

This appears to be called by the binding stuff within Aurelia. I'm going to move this to boolean | string for now and align the if statement to match for clarity. If something else comes later on down the road, we can re-visit this bit.

}

public themeChanged(newValue: any) {
this.styleEngine.applyTheme(this, newValue);
}

public disabledChanged(newValue: boolean | string) {
// ensure we cast empty string as true
if (typeof this.disabled === 'string' && this.disabled === '') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you mean if (typeof newValue === 'string' && newValue = '') {?

Copy link
Contributor Author

@chrsmrtn- chrsmrtn- Jun 8, 2017

Choose a reason for hiding this comment

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

Yep that I did!

will fix to:

if (typeof newValue === 'string' && newValue === '') {

Funny thing is, in my testing that if block was never hit as the binding code is sending boolean values for the update task all the time.

@serifine serifine merged commit a16f47f into aurelia:master Jun 9, 2017
@chrsmrtn- chrsmrtn- deleted the ux-button-disabled-click-issue branch June 9, 2017 15:08
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.

ux-button click event still fires despite being disabled
5 participants