odoo / owl

OWL: A web framework for structured, dynamic and maintainable applications
https://odoo.github.io/owl/
Other
1.16k stars 346 forks source link

slot: access to intermediary component's rendering context #693

Closed seb-odoo closed 2 years ago

seb-odoo commented 4 years ago

The use case in Odoo: the Popover component and especially its displayed state.

The element on which the popover is bound (which is defined as a slot) can have a different style depending on whether the popover is open or not.

This information is only known by the popover component itself, not by the parent calling it, and I would like to have a way to access this information from the slot's element that is defined in the parent, but due to the slot mechanisms, it only has access to the parent context.

I would suggest to add a special key on that context to still be able to access the real/intermediary rendering context.

ged-odoo commented 4 years ago

I checked the Vue documentation and they are very clear that the content inside a slot does not have access to the parent scope.

I am also not in favor of such a change:

  1. I don't like magic keys
  2. In your usecase, there is a standard solution: the Popover component can simply set a is-opened class on itself, and the content can use this to style itself. This is what you would do in Vue as well.

I suggest to wait for a stronger usecase, and then we will decide what the best way to move forward is

seb-odoo commented 4 years ago

Please read the Scoped Slots paragraph on the same page, it is exactly the answer to the current use case: https://vuejs.org/v2/guide/components-slots.html#Scoped-Slots

ged-odoo commented 4 years ago

ooh, i didn't see it at first! This also looks like a good API

seb-odoo commented 4 years ago

I didn't know either, I just found it. I'm glad to see it's pretty much what I suggested except instead of a magic key, we can explicitly define it, which is even better. So if we go with that I would consider the issue resolved of course.

ged-odoo commented 2 years ago

done in owl 2