question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

feat: iOS search bar in header styling support

See original GitHub issue

Feature Request

Ionic version:

[x] 5.x

Describe the Feature Request

While working with a member of the community, we discovered that there is a design oddity when placing an ion-searchbar inside an ion-toolbar inside an ion-header.

ion-searchbar will be given a padding-bottom: 15px; value when the ion-toolbar .sc-ion-searchbar-ios-h CSS selector is applied.

When given padding-bottom: 15px, the ion-searchbar does not vertically align correctly with other elements placed within the ion-toolbar.

Describe Preferred Solution

It might be beneficial to add styling that reduces the padding-bottom value of an ion-searchbar component when it’s placed inside an ion-toolbar inside of an ion-header, something to the effect of:

ion-header ion-toolbar .sc-ion-searchbar-ios-h {
  padding-bottom: // some better value
}

Describe Alternatives

It’s always possible to introduce a custom CSS class at the project level that overrides the padding-bottom value set by the framework. However, this design paradigm appears to be popular in the mobile world and might be worth supporting within the Ionic Framework.

Related Code

A repro has been built that showcases the issue. It can be found here: https://github.com/ehorodyski-ionic/ng-searchbar-in-header

The relevant portion of code to reproduce this issue is:

<ion-header [translucent]="false">
  <ion-toolbar>
    <ion-buttons slot="start">
      <ion-menu-button></ion-menu-button>
    </ion-buttons>
    <ion-searchbar></ion-searchbar>
    <ion-buttons slot="end">
      <ion-icon slot="icon-only" name="add-sharp"></ion-icon>
    </ion-buttons>
  </ion-toolbar>
</ion-header>

Additional Context

The screenshot below highlights the UX when running on an iOS simulator. Ideally, the ion-searchbar would be better vertically aligned with the other elements contained within the ion-toolbar. header

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
brandyscarneycommented, Jun 8, 2020

Thanks for the issue! This is actually by design to match the iOS spec. You can see where the numbers come from this photo (this was taken awhile ago of native):

Here are some examples of the searchbar natively by itself:

Safari search App Store search
IMG_7410 IMG_7411
IMG_7413 IMG_7412

The buttons inside of a toolbar with a searchbar are aligned to the top with the searchbar. This is an unusual design for iOS though, as native apps don’t put anything else in a toolbar with a searchbar. We could revisit the padding on searchbar to make sure it still aligns with native, but when that decision was made it was compared and lined up. I believe this may be more of a documentation issue.

1reaction
dorontalcommented, Aug 31, 2021

+1

Had recently asked about this in the Forum, got no answer so I’m here.

My template is (it has no scss):

<ion-header>
    <ion-toolbar>
        <ion-buttons *ngIf="!showSearchbar" slot="start">
            <ion-menu-button></ion-menu-button>
        </ion-buttons>
        <ion-title *ngIf="!showSearchbar">Explore</ion-title>
        <ion-searchbar *ngIf="showSearchbar" showCancelButton="always"
                       [(ngModel)]="searchQuery"
                       (ionCancel)="showSearchbar = false"
                       (ionChange)="autocomplete()"
                       (keyup.enter)="search()"
                       placeholder="Search Tracktunes"></ion-searchbar>
        <ion-buttons slot="end">
            <ion-button *ngIf="!showSearchbar" (click)="showSearchbar = true">
                <ion-icon slot="icon-only" name="search"></ion-icon>
            </ion-button>
        </ion-buttons>
    </ion-toolbar>
</ion-header>

and the iPhone4 simulation looks like this:

iPhone4sim

NOTE: when I add the following to the page’s scss file, it has no effect (tried it because of the above comment):

.ios ion-header ion-toolbar {
    padding-top: 15px;
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

feat: iOS search bar in header styling support · Issue #21455
The buttons inside of a toolbar with a searchbar are aligned to the top with the searchbar. This is an unusual design for...
Read more >
UISearchController and darker barTintColor under iOS 13
I'm facing a few problems with UISearchController under iOS 13. I'm using a UISearchController within a UITableViewController in order to search for ...
Read more >
Everything New With Spotlight Search in iOS 16 - MacRumors
The iPhone and iPad have a built-in intelligent search feature called Spotlight, which is designed to search through apps, files, ...
Read more >
Create a React Native search bar from scratch - LogRocket Blog
React Native is a JavaScript-based framework, which makes it pretty easy to build cross-platform (iOS and Android) mobile applications. Watch ...
Read more >
SwiftUI Search Bar in the Navigation Bar - eppz!
Using UINavigationItem searchController property ... UIKit offers a pretty convenient way to implement a native search bar embedded into the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found