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

Add @ to onClick in BsModal::Footer submit button #2123

Merged

Conversation

SanderKnauff
Copy link
Contributor

As part of the Typescript conversion of bs-modal, I noticed that the @ on @onClick was missing for the submit button.

I have added tests for the submit and close button, and they seem to be fine with or without the @, but to keep in line with Ember's usual style, we should put the @ in there anyway.

SanderKnauff added a commit to SanderKnauff/ember-bootstrap that referenced this pull request Apr 10, 2024
@jelhan
Copy link
Contributor

jelhan commented Apr 12, 2024

Great catch. My assumption would be that onClick seems to work as well for most use cases as Ember sets the onclick property of the button element.

If that assumptions is correct, the handleClick logic of <BsButton> would be skipped:

/**
* @method click
* @private
*/
@action
async handleClick(e: MouseEvent) {
const { bubble, onClick, preventConcurrency } = this.args;
if (typeof onClick !== 'function') {
return;
}
// Shouldn't we prevent propagation regardless if `@onClick` is a function?
if (!bubble) {
e.stopPropagation();
}
if (preventConcurrency && this.isPending) {
return;
}
this.state = 'pending';
try {
await onClick(this.args.value);
if (!this.isDestroyed) {
this.state = 'fulfilled';
}
} catch (error) {
if (!this.isDestroyed) {
this.state = 'rejected';
}
throw error;
}
}
This should have the affect that promise state is not handled correctly with the button.

The promise state is used in <BsButton> to control the disabled argument. If my assumption is correct, the button is not disabled while a promise triggered by it is still running. That would be a bug, which is just not covered by our existing tests.

Would be great if you could double check that. Maybe even add a test case for it.

@jelhan jelhan added the bug label Apr 12, 2024
@SanderKnauff
Copy link
Contributor Author

SanderKnauff commented Apr 12, 2024

After testing your assumption seems to be correct. It uses the browser's onclick rather than delegating it to BsButton. I have a hard time getting the test to work as expected however.

For some reason, the isPending getter of BsButton does not update after the _state field changes, which in turn causes the disabled state not to update. Something with Ember's tracking is doing something weird and I can yet put my finger on what it is.

Edit:
The autotracking was not tracking because the disabled attribute of the element was being overwritten by the BsModal::Footer. I'll update with the test

…ng promise

Due to a missing `@`, the promise was initially ignored and two separate click handlers would fire for the submit button: One in BsModal::Footer and the other in BsButton.
By adding back the `@` and conditionally setting the `disabled` field on the submit button, any promise that is returned from the `@onSubmit` function will now disable the button until the promise is settled
@SanderKnauff
Copy link
Contributor Author

To get the pending state to work as expected, I had to create a modifier for conditionally setting an attribute on an element. The disabled attribute on the Footer submit button was interfering with the default disabled behavior on BsButton.
In the changed situation, the disabled attribute will only exist on the footer if @submitDisabled is set. In all other cases, BsButton, or the button component provided by the consumer, will handle the disabled state.

Copy link
Contributor

@jelhan jelhan left a comment

Choose a reason for hiding this comment

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

Thanks a lot. Didn't had the time for a detailed review yet. But what I have seen so far looks great. Only one small change to dependency management.

@SanderKnauff
Copy link
Contributor Author

Thanks a lot. Didn't had the time for a detailed review yet. But what I have seen so far looks great. Only one small change to dependency management.

That's fine! I don't see the comment about the dependency management though. Should something be changed in ember-bootstrap/package.json?

@jelhan
Copy link
Contributor

jelhan commented Apr 13, 2024

Thanks a lot. Didn't had the time for a detailed review yet. But what I have seen so far looks great. Only one small change to dependency management.

That's fine! I don't see the comment about the dependency management though. Should something be changed in ember-bootstrap/package.json?

Arghs. Somehow my review comment got lost. In short:

I think ember-modifier should be a peer dependency. It is added as a dependency for every app in Ember CLI blueprints.

Ember Bootstrap introduces a peer dependency on ember-modifier indirectly already today. Ember Bootstrap depends on ember-style-modifier. Ember-style-modifier has a peer dependency on ember-modifier.

Supported range for ember-modifier peer dependency should be the same as ember-style-modifier supports. In that case it wouldn't be a breaking change. At least in my understanding of our informal SemVer commitment for dependency management.

@SanderKnauff
Copy link
Contributor Author

Ember Bootstrap introduces a peer dependency on ember-modifier indirectly already today. Ember Bootstrap depends on ember-style-modifier. Ember-style-modifier has a peer dependency on ember-modifier.

Supported range for ember-modifier peer dependency should be the same as ember-style-modifier supports. In that case it wouldn't be a breaking change. At least in my understanding of our informal SemVer commitment for dependency management.

Ah, that makes sense. I've check ember-style-modifier, but that does not seem to specifically declare ember-modifier as peer dependency. I've copied version the range of ember-modifier that ember-style-modifier supports now

@jelhan
Copy link
Contributor

jelhan commented Apr 13, 2024

I've check ember-style-modifier, but that does not seem to specifically declare ember-modifier as peer dependency.

Good catch! I assumed it does. But it does not. Same for ember-popper-modifier. Both declare it as dependencies only. I guess that should be changed upstream as well at some point.

Copy link
Contributor

@jelhan jelhan left a comment

Choose a reason for hiding this comment

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

Looks good to me. Especially the improved test coverage. Great job!

@SanderKnauff SanderKnauff merged commit 9c96402 into ember-bootstrap:master Apr 13, 2024
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants