-
-
Notifications
You must be signed in to change notification settings - Fork 56
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
fix(button): add disable button behavior #76
Conversation
src/button/ux-button.ts
Outdated
@@ -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; |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
src/button/ux-button.ts
Outdated
@@ -29,12 +29,24 @@ export class UxButton implements Themable { | |||
if (this.theme) { | |||
this.styleEngine.applyTheme(this, this.theme); | |||
} | |||
|
|||
if (this.disabled || this.disabled === '') { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
src/button/ux-button.ts
Outdated
@@ -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; |
There was a problem hiding this comment.
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
src/button/ux-button.ts
Outdated
@@ -29,12 +29,24 @@ export class UxButton implements Themable { | |||
if (this.theme) { | |||
this.styleEngine.applyTheme(this, this.theme); | |||
} | |||
|
|||
if (this.disabled || this.disabled === '') { |
There was a problem hiding this comment.
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.
src/button/ux-button.ts
Outdated
@@ -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; |
There was a problem hiding this comment.
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.
src/button/ux-button.ts
Outdated
@@ -29,12 +29,24 @@ export class UxButton implements Themable { | |||
if (this.theme) { | |||
this.styleEngine.applyTheme(this, this.theme); | |||
} | |||
|
|||
if (this.disabled || this.disabled === '') { |
There was a problem hiding this comment.
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.
src/button/ux-button.ts
Outdated
} | ||
|
||
public themeChanged(newValue: any) { | ||
this.styleEngine.applyTheme(this, newValue); | ||
} | ||
|
||
public disabledChanged(newValue: any) { |
There was a problem hiding this comment.
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) {
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
src/button/ux-button.ts
Outdated
} | ||
|
||
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 === '') { |
There was a problem hiding this comment.
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 = '') {
?
There was a problem hiding this comment.
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.
this adds in disabled behavior when defined for
<ux-button></ux-button>
resolves #75