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

container function to generate container element #17143

Merged
merged 1 commit into from
May 30, 2018

Conversation

melitele
Copy link
Contributor

I've added a container function to options that will allow client to provide a different container element. The default version of container function creates container element as before. I believe this is in line with the item function that customizes creating item elements.

This addresses my use case where container element cannot reuse the input element parent
because the input parent clips container's content. It also addresses a case when input element has to be next to it's original siblings.

It also solves #17086 & #16718

Thank you for consideration.

className: "awesomplete",
around: input
});
this.container = this.container(input);
Copy link
Owner

Choose a reason for hiding this comment

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

Do note that this means the this.container() function is overwritten and not accessible anymore. Are we sure we don't need to access it again?

Copy link
Contributor Author

@melitele melitele May 29, 2018

Choose a reason for hiding this comment

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

If I am reading the original code correctly, the container element is never re-created during the object life cycle. That's why I've let the function to be overwritten. I can change the field used for the container function - do you have a preference for the field name?

Thank you for looking at this PR.

Copy link
Owner

Choose a reason for hiding this comment

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

Nah, I think container is a good name. Perhaps we can store the constructor options somewhere? Like this.options? Then we still have access to the function, so you can compare it to the default function in the check in destroy() instead of the less foolproof way you're checking now.

Copy link
Contributor Author

@melitele melitele May 30, 2018

Choose a reason for hiding this comment

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

Done. Added this.options to hold the original options passed to Awesomplete constructor. Checking this.options.container in destroy() and cleaning up the container element only when this.options.container is not set i.e. when container is originally created by Awesomplete.

Copy link
Owner

@LeaVerou LeaVerou left a comment

Choose a reason for hiding this comment

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

Hey, thanks! Looks good overall, please reply to these 2 comments.

awesomplete.js Outdated
@@ -203,11 +201,13 @@ _.prototype = {
$.unbind(this.input, this._events.input);
$.unbind(this.input.form, this._events.form);

//move the input out of the awesomplete container and remove the container and its children
var parentNode = this.container.parentNode;
if (this.input.parentNode === this.container) {
Copy link
Owner

Choose a reason for hiding this comment

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

What's the reasoning behind this if?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The container element should only be destroyed by the Awesomplete if it was created by the Awesomplete - the condition of the if is true when the container element was created by the default method of creating it.

Copy link
Owner

Choose a reason for hiding this comment

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

Ok, fair enough.

Copy link
Owner

Choose a reason for hiding this comment

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

But see my other comment about improving the check.

Copy link
Owner

Choose a reason for hiding this comment

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

Basically, what do we want if the container is custom, but also a parent of the input? Do we want to destroy it or not? That affects what we check for here.

addresses a use case where container element cannot reuse input element parent
because input parent clips container content

also solves LeaVerou#17086 & LeaVerou#16718
@melitele melitele force-pushed the container-config branch from 4b6e170 to bf33271 Compare May 30, 2018 05:36
@LeaVerou LeaVerou merged commit 466bb15 into LeaVerou:gh-pages May 30, 2018
@LeaVerou
Copy link
Owner

LeaVerou commented May 30, 2018

Nice, merged! Thank you so much!

@melitele
Copy link
Contributor Author

Thank you for taking my PR. And thank you for making and sharing this component.

@melitele melitele deleted the container-config branch June 1, 2018 19:32
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.

2 participants