tried to be clever and created my navbar as a component, as the functionality is often the same throughout the app, however I am getting some styling issues with left and right buttons in it.
This is caused by the navbar’s content projection. The navbar component is looking for direct children elements in order to position them. Since you are wrapping the children elements in another element it can’t find them and is placing them incorrectly. Please see this issue:
You should be able to change it to something like this:
So while that does work…sort of, the reason why I went away from that approach is in the iOS emulator, the top is now no longer calculated for as you can see below. Having the <ion-navbar> in there with the <ion-content> fixed that, but with the original issue with the button placement however
Yeah, so this is the problem with custom wrapper components. We can make them work with content projection and then we run into problems with styling. The styling needs to get the toolbar that is the first direct child of the header. So if you have the following markup:
It will look for ion-header > .toolbar:first-child because it doesn’t want to add any extra styling to the second toolbar. So when you wrap it in a custom component the markup ends up something like this:
and the .toolbar is no longer the direct child of the ion-header, nor would it be the first-child. As a workaround, you could copy the Sass that includes this function in your custom header:
It’s a rather complex issue to solve because when you start modifying the structure we no longer know which elements to look for. I hope that helps to explain why this is happening. We don’t have a great solution for this yet.
I’ve got a similar problem with creating the header as a custom component. I tried the following solution, but this did not work. Since this was last updated in July, has there been any updated solution since?