Change Material 2 tab width without affecting tabs in parent component? - css

I have a child search component on every view that has tabs. Since these tabs only have icons in the tab label I have to style them to have a smaller width.
I found something that works:
/deep/ .mat-tab-label {
min-width: 80px !important;
}
However, this also affects the tabs in the parent component but without the /deep/ and !important the tabs don't change their width.
I've tried using all forms of ViewEncapsulation but none of them get the job done.
The tab structure is basically this:
<md-tab-group [selectedIndex]="selectedTabIndex">
<md-tab>
<ng-template md-tab-label><i class="fa fa-users"></i> {{'common_users' |
translate | capitalize}}
</ng-template>
<search-component></search-component>
</md-tab>
</md-tab-group>
The search component also has tabs in it:
<md-tab-group>
<md-tab>
<template md-tab-label>
<i class="fa fa-search" mdTooltip="{{'common_simplesearch' | translate | capitalize}}"></i>
</template>
<div fxLayout="column">
<form>
<md-input-container
*ngFor="let option of simpleSearchOptions; let i = index; let last = last" fxFlex="100%"
style="margin-right: 10px; margin-top: 5px;">
<input mdInput
type="text"
[(ngModel)]="option.value"
name="searchQuery{{i}}">
</md-input-container>
<div fxlayout="row">
<button md-raised-button mdTooltip="{{'common_search' | translate | capitalize}}" color="primary"
type="submit"
(keypress)="onEnter($event, searchSet)"
(click)="search(searchSet)">
{{'common_search' | translate | capitalize}}
</button>
<button *ngIf="canClear != false" md-raised-button mdTooltip="{{'common_clearSearch' | translate |
capitalize}}" (click)="clearSearch()"><i class="fa fa-eraser"></i>
</button>
</div>
</form>
</div>
</md-tab>
<md-tab>
<template md-tab-label>
<i class="fa fa-search-plus" mdTooltip="{{'common_advancedsearch' | translate | capitalize}}"></i>
</template>
<div fxlayout="column">
<form (ngSubmit)="search(searchSet)">
<div *ngFor="let searchItem of searchSet.searchItems; let i = index; let first = first; let last = last">
<md-select [ngModel]="searchItemType[i]"
(change)="onSearchTypeChange(searchItem, i)"
name="searchBy{{i}}" fxFlex="100">
<md-option [value]="stringify(option)" *ngFor="let option of searchOptions">{{option.display | translate |
capitalize}}
</md-option>
</md-select>
<div *ngIf="searchBy == 'identifier'">
<md-select [(ngModel)]="searchItem.key" name="idType" fxFlex="100">
<md-option *ngFor="let option of tokenSearchOptions" [value]="option">{{option | translate | capitalize}}
</md-option>
</md-select>
</div>
<md-select [(ngModel)]="searchItem.modifier" name="searchType{{i}}" fxFlex>
<md-option [value]="modifier.value" *ngFor="let modifier of searchModifiers[i]; let i = index">
{{modifier.display | translate |
capitalize}}
</md-option>
</md-select>
<md-input-container fxFlex="100">
<input mdInput
type="text"
placeholder="{{'common_search' | translate | capitalize}}"
[(ngModel)]="searchItem.value"
name="searchQuery{{i}}">
</md-input-container>
<a class="btn btn-alert btn-lg" (click)="addSearchItem()" [hidden]="!last">
<i class="ion-ios-plus-outline"></i>
</a>
<a class="btn btn-alert btn-lg" (click)="removeSearchItem(searchItem)" [hidden]="first || !last"><i
class="ion-ios-minus-outline"></i></a>
</div>
<button md-raised-button color="primary"
[disabled]="!searchSet.searchItems[0].key || !searchSet.searchItems[0].modifier || !searchSet.searchItems[0].value"
(keypress)="onEnter($event, searchSet)" (click)="search(searchSet)">{{'common_search' |
translate
| capitalize}}
</button>
<button md-raised-button (click)="clearSearch()">{{'common_clearSearch' | translate |
capitalize}}
</button>
</form>
</div>
</md-tab>
<md-tab>
<template md-tab-label>
<i class="fa fa-bookmark-o"></i>
</template>
Saved searches
</md-tab>
</md-tab-group>
How can I style the tabs only in the child component without affecting the parent?

Related

Why does font change for all of Bootstrap but not Angular header?

I want to change the font across my whole website (effectively changing the font globally), so I've overwritten the Bootstrap font by updating my styles.scss file as below:
$theme-colors:(
"primary": #84329b,
);
#import '../node_modules/bootstrap/scss/bootstrap';
html, body { height: 100%; }
body { margin: 0; font-family: 'MuseoModerno', cursive !important; }
This works successfully, however, the font in my header does not change in-line with this (see the below image).
How can I ensure the font changes for the header?
For completeness, I've included the html code for my header below. As you can see, I've attempted to update the font specifically on the header, as it wasn't working after updating the styles.scss file. Unfortunately, this doesn't seem to work either.
<link href="https://fonts.googleapis.com/css2?family=MuseoModerno:wght#200&display=swap" rel="stylesheet">
<mat-sidenav-container class="sidenav-container">
<!---links to appear in the sidenav if the device is a mobile-->
<mat-sidenav
#drawer
class="sidenav"
fixedInViewport
[attr.role]="(isHandset$ | async) ? 'dialog' : 'navigation'"
[mode]="(isHandset$ | async) ? 'over' : 'side'"
[opened]="false"
>
<mat-toolbar>Menu</mat-toolbar>
<mat-nav-list>
<a mat-list-item routerLink="/catalogue" (click)="drawer.close()"
>Catalogue</a
>
<a mat-list-item routerLink="/notepads" (click)="drawer.close()"
>Explore Pads</a
>
<hr class="divider-line">
<a mat-list-item routerLink="/login" (click)="drawer.close()">Login</a>
<a mat-list-item routerLink="/sign-up" (click)="drawer.close()"
>Sign Up</a
>
</mat-nav-list>
<hr class="divider-line">
</mat-sidenav>
<!---content below is for everything contained along the header, mobile or not-->
<mat-sidenav-content>
<mat-toolbar>
<!---this is the menu icon to appear on mobile-->
<button
mat-icon-button
(click)="drawer.toggle()"
*ngIf="isHandset$ | async"
>
<mat-icon>menu</mat-icon>
</button>
<!---spacer between the mobile menu button and Padder logo-->
<span class="left-spacer" *ngIf="isHandset$ | async"></span>
<!---Padder logo for desktop-->
<span *ngIf="!(isHandset$ | async)" class="logo" routerLink="/"
><img
class="logo-image"
src="../../../assets/imgs/padder-logo.png"
alt="Padder Logo"
/></span>
<!--links for the header when the device is not a handset-->
<div class="nav-links" *ngIf="!(isHandset$ | async)">
<a mat-button routerLink="/catalogue">Catalogue</a>
<a mat-button routerLink="/notepads">Explore Pads</a>
</div>
<div class="search-container" *ngIf="!(isHandset$ | async)">
<mat-form-field class="header-search">
<input matInput placeholder="Search for products or pads.." />
</mat-form-field>
</div>
<!---Padder logo for mobile-->
<span *ngIf="isHandset$ | async" class="logo" routerLink="/"
><img
class="logo-image-mobile"
src="../../../assets/imgs/padder-logo.png"
alt="Padder Logo"
/></span>
<!---spacer between Padder logo and login button-->
<span class="right-spacer" *ngIf="isHandset$ | async"></span>
<!--login / sign-up button to be shown when user not logged in, desktop-->
<div class="login-links">
<a mat-button routerLink="/login" *ngIf="!(isHandset$ | async)"
>Login</a
>
<a mat-button routerLink="/login" *ngIf="!(isHandset$ | async)"
>Sign Up</a
>
</div>
<!---search icon to be shown when the user is on mobile-->
<div>
<button mat-icon-button *ngIf="isHandset$ | async">
<mat-icon>search</mat-icon>
</button>
</div>
<!---dropdown to be down when the user is logged into the website-->
<!---
<div>
<button mat-icon-button [matMenuTriggerFor]="menu">
<mat-icon>more_vert</mat-icon>
</button>
<mat-menu #menu="matMenu">
<a mat-menu-item routerLink="/profile">
<span>Profile</span>
</a>
<a mat-menu-item href="">
<button mat-stroked-button>Logout</button>
</a>
</mat-menu>
</div>--->
</mat-toolbar>
<ng-content></ng-content>
</mat-sidenav-content>
</mat-sidenav-container>
In you styles.scss, do the following:
#import "https://fonts.googleapis.com/css2?family=MuseoModerno:wght#200&display=swap";
* {
font: 500 20px/32px Roboto, 'MuseoModerno', sans-serif !important
}
This will definitely work

Is there a way to make mat-menu-item same size as mat-button on click?

I would like to make it so that when I click the mat-button, the menu items would be the same size and push everything else down. Below are attached images of the current situation and desired.
Current closed dropdown
Current opened dropdown
Desired closed dropdown
Here is my HTML code:
<mat-footer>
<div class="footerLinks">
<span *ngFor="let footerLink of footerContent.footerLinks">
<span *ngIf="footerLink.footerDrop.length > 1 else single">
<a mat-button [matMenuTriggerFor]="subLinks" href="javascript:void(0)" title={{footerLink.subFooterTitle}}>{{footerLink.subFooterTitle}}
<mat-icon>arrow_drop_down</mat-icon>
</a>
<mat-menu #subLinks="matMenu" arrowPosition="up">
<a mat-menu-item *ngFor="let footerDrop of footerLink.footerDrop" href={{footerDrop.subLink}} target={{footerDrop.linktarget}} title={{footerDrop.footerSubTitle}}>{{footerDrop.footerSubTitle}}</a>
</mat-menu>
</span>
<ng-template #single >
<a mat-button *ngFor="let footerDrop of footerLink.footerDrop" href={{footerDrop.subLink}} target={{footerDrop.linktarget}} title={{footerDrop.footerSubTitle}}>{{footerDrop.footerSubTitle}}</a>
</ng-template>
</span>
</div>
<div class="social">
<span *ngFor="let socialLink of footerContent.socialLinks">
<a mat-flat-button class="{{socialLink.socialMediaService}}-icon" href={{socialLink.url}} title={{socialLink.socialMediaService}} target={{socialLink.linktarget}}></a>
</span>
</div>
<div class="terms">
<mat-copywrite-footer [innerHTML]="footerContent.finePrint.value"> </mat-copywrite-footer>
</div>
</mat-footer>

Search input with an icon Bootstrap

No clue how I can do this, since BS 4 doesn't support glyphicons. Do I set it up as a background or do I apply different positioning to a font-awesome icon?
This is my code so far:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<div class="form-group col-md-4">
<input class="form-control rounded-0 py-2" type="search" value="search" id="example-search-input">
</div>
<!-- /.form-group -->
I want to use this font-awesome icon. And I've tried adding it as a background-image too, as in:
.form-control {
background-image: url('https://res.cloudinary.com/dt9b7pad3/image/upload/v1502810110/angle-down-dark_dkyopo.png');
background-position: right center 5px;
}
But that doesn't do anything. The only way I can think of is to add font-awesome icon and then set the positioning to absolute, right? But I'm not sure if that's the 'clean' and correct way to do it? Do I need to take a different approach to this? Someone help! Thank you!
Bootstrap 5 Beta - (update 2021)
<div class="input-group">
<input class="form-control border-end-0 border rounded-pill" type="text" value="search" id="example-search-input">
<span class="input-group-append">
<button class="btn btn-outline-secondary bg-white border-start-0 border rounded-pill ms-n3" type="button">
<i class="fa fa-search"></i>
</button>
</span>
</div>
Demo
Bootstrap 4 (original answer)
Why not use an input-group?
<div class="input-group col-md-4">
<input class="form-control py-2" type="search" value="search" id="example-search-input">
<span class="input-group-append">
<button class="btn btn-outline-secondary" type="button">
<i class="fa fa-search"></i>
</button>
</span>
</div>
And, you can make it appear inside the input using the border utils...
<div class="input-group col-md-4">
<input class="form-control py-2 border-right-0 border" type="search" value="search" id="example-search-input">
<span class="input-group-append">
<button class="btn btn-outline-secondary border-left-0 border" type="button">
<i class="fa fa-search"></i>
</button>
</span>
</div>
Or, using a input-group-text w/o the gray background so the icon appears inside the input...
<div class="input-group">
<input class="form-control py-2 border-right-0 border" type="search" value="search" id="example-search-input">
<span class="input-group-append">
<div class="input-group-text bg-transparent"><i class="fa fa-search"></i></div>
</span>
</div>
Alternately, you can use the grid (row>col-) with no gutter spacing:
<div class="row no-gutters">
<div class="col">
<input class="form-control border-secondary border-right-0 rounded-0" type="search" value="search" id="example-search-input4">
</div>
<div class="col-auto">
<button class="btn btn-outline-secondary border-left-0 rounded-0 rounded-right" type="button">
<i class="fa fa-search"></i>
</button>
</div>
</div>
Or, prepend the icon like this...
<div class="input-group">
<span class="input-group-prepend">
<div class="input-group-text bg-transparent border-right-0">
<i class="fa fa-search"></i>
</div>
</span>
<input class="form-control py-2 border-left-0 border" type="search" value="..." id="example-search-input" />
<span class="input-group-append">
<button class="btn btn-outline-secondary border-left-0 border" type="button">
Search
</button>
</span>
</div>
Demo of all Bootstrap 4 icon input options
Example with validation icons
I made another variant with dropdown menu (perhaps for advanced search etc)..
Here is how it looks like:
<div class="input-group my-4 col-6 mx-auto">
<input class="form-control py-2 border-right-0 border" type="search" placeholder="Type something..." id="example-search-input">
<span class="input-group-append">
<button type="button" class="btn btn-outline-primary dropdown-toggle dropdown-toggle-split border border-left-0 border-right-0 rounded-0" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="sr-only">Toggle Dropdown</span>
</button>
<button class="btn btn-outline-primary rounded-right" type="button">
<i class="fas fa-search"></i>
</button>
<div class="dropdown-menu dropdown-menu-right">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
<div role="separator" class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Separated link</a>
</div>
</span>
</div>
Note: It appears green in the screenshot because my site main theme is green.
Here is an input box with a search icon on the right.
<div class="input-group">
<input class="form-control py-2 border-right-0 border" type="search" placeholder="Search">
<div class="input-group-append">
<div class="input-group-text" id="btnGroupAddon2"><i class="fa fa-search"></i></div>
</div>
</div>
Here is an input box with a search icon on the left.
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text" id="btnGroupAddon2"><i class="fa fa-search"></i></div>
</div>
<input class="form-control py-2 border-right-0 border" type="search" placeholder="Search">
</div>
Here's a fairly simple way to achieve it by enclosing both the magnifying glass icon and the input field inside a div with relative positioning.
Absolute positioning is applied to the icon, which takes it out of the normal document layout flow. The icon is then positioned inside the input. Left padding is applied to the input so that the user's input appears to the right of the icon.
Note that this example places the magnifying glass icon on the left instead of the right. This is recommended when using <input type="search"> as Chrome adds an X button in the right side of the searchbox. If we placed the icon there it would overlay the X button and look fugly.
Here is the needed Bootstrap markup.
<div class="position-relative">
<i class="fa fa-search position-absolute"></i>
<input class="form-control" type="search">
</div>
...and a couple CSS classes for the things which I couldn't do with Bootstrap classes:
i {
font-size: 1rem;
color: #333;
top: .75rem;
left: .75rem
}
input {
padding-left: 2.5rem;
}
You may have to fiddle with the values for top, left, and padding-left.
in ASPX bootstrap v4.0.0, no beta (dl 21-01-2018)
<div class="input-group">
<asp:TextBox ID="txt_Product" runat="server" CssClass="form-control" placeholder="Product"></asp:TextBox>
<div class="input-group-append">
<asp:LinkButton ID="LinkButton3" runat="server" CssClass="btn btn-outline-primary">
<i class="ICON-copyright"></i>
</asp:LinkButton>
</div>
It is also possible with position-absolute in Bootstrap 5:
<form class="d-flex flex-row position-relative">
<input type="search" class="form-control" id="example-search-input">
<button class="btn btn-outline-success border-0 position-absolute end-0" type="submit">
<i class="fa fa-search"></i> Search
</button>
</form>
With Bootstrap 5 and bootstrap-icons library:
<div class="input-group mb-3">
<input type="text" class="form-control" placeholder="Search"
aria-describedby="button-addon">
<button class="btn btn-outline-secondary" type="button" id="button-addon"><i class="bi bi-search"></i></button>
</div>
you can also do in this way using input-group
<div class="input-group">
<input class="form-control"
placeholder="I can help you to find anything you want!">
<div class="input-group-addon" ><i class="fa fa-search"></i></div>
</div>
codeply

select box in not displaying properly

Select list is not displaying properly.
Please see the images..
some height is conflicting, I am using angular ui-select for select list.
<ui-select id="viewSelector" class="viewSelector input-small" ng-model="dashboard.refresh" theme="selectize" style="width: 120px;" ng-change="autoRefreshUpdated()">
<ui-select-match placeholder="Select Interval">{{$select.selected}}</ui-select-match>
<ui-select-choices repeat="interval in autoRefreshIntervals">
<div ng-bind-html="interval"></div>
</ui-select-choices>
</ui-select>
Code rendered as :
<div class="viewSelector input-small ui-select-container selectize-control single ng-valid ng-touched ng-dirty ng-valid-parse" ng-class="{'open': $select.open}" id="viewSelector" ng-model="dashboard.refresh" theme="selectize" style="width: 120px;/* height: 10px !important; */" ng-change="autoRefreshUpdated()">
<div class="selectize-input" ng-class="{'focus': $select.open, 'disabled': $select.disabled, 'selectize-focus' : $select.focus}" ng-click="$select.activate()">
<div ng-hide="($select.open || $select.isEmpty())" class="ui-select-match" ng-transclude="" placeholder="Select Interval"><span class="ng-binding ng-scope">5s</span>
</div>
<input type="text" autocomplete="off" tabindex="-1" class="ui-select-search ui-select-toggle ng-pristine ng-valid ng-touched ng-hide" ng-click="$select.toggle($event)" placeholder="Select Interval" ng-model="$select.search" ng-hide="!$select.searchEnabled || ($select.selected && !$select.open)" ng-disabled="$select.disabled" aria-label="Select box">
</div>
<div ng-show="$select.open" class="ui-select-choices ui-select-dropdown selectize-dropdown single ng-scope ng-hide" repeat="interval in autoRefreshIntervals" style="opacity: 1;">
<div class="ui-select-choices-content selectize-dropdown-content">
<div class="ui-select-choices-group optgroup" role="listbox">
<div ng-show="$select.isGrouped" class="ui-select-choices-group-label optgroup-header ng-binding ng-hide" ng-bind="$group.name"></div>
</div>
</div>
</div>
<ui-select-single></ui-select-single>
<input ng-disabled="$select.disabled" class="ui-select-focusser ui-select-offscreen ng-scope" type="text" id="focusser-1" aria-label="Select box focus" aria-haspopup="true" role="button">
</div>

Bootstrap NavBar non-collapsable input field

I have a nav Bar with a input field and a couple links
but I want just the links to be collapsed.
I'm trying to get this work for a few hours with no success.
It doesn't stay on a single row
What I want is something like this
Desktop
| [Brand Name] [Input field___________________________(Search)] [Button] [Button] |
Mobile
| [Brand Name] [Input field (Search)] [#] |
|---------------------------------------------|
| Button |
| Button |
http://www.bootply.com/G1JJxeMQA0#
another atempt http://www.bootply.com/n3raobttyd
Take a look at this:
https://jsfiddle.net/9L3b08zf/
If you change the size of the result grid, you will see how the link will jump form side to bottom.
I have used the bootstrap grid to achieve this.
<div class="row">
<div class="col-md-6 search">
<form class="navbar-form" role="search" method="get" id="search-form" name="search-form">
<div class="input-group">
<input type="text" class="form-control" placeholder="e.g.: www.google.com" id="query" name="query" value="">
<div class="input-group-btn">
<button type="submit" class="btn btn-success"><span class="glyphicon glyphicon-search"> Locate</span></button>
</div>
</div>
</form>
</div>
<div class="col-md-6 buttons">
<div class="collapse navbar-collapse navbar-ex1-collapse ">
<div class="row">
<div class="col-md-6"><a data-toggle="modal" href="#" data-target="#">Login</a></div>
<div class="col-md-6"><a data-toggle="modal" href="#" data-target="#">Register</a></div>
</div>
</div>
</div>

Resources