Add Custom Icon in Ionic 2 - ionic-framework

I am using Ionic 2 for developing my App. I want to use my custom icons in my app like we use ionic 2 icons using tag. Eg:
<ion-icon name="my-custom-icon"></ion-icon>
How can i achieve this? Is there any recommended way to doing this?

This is the easiest way I've found, from the forums at https://forum.ionicframework.com/t/anyway-to-custom-the-tabbars-icon-with-my-own-svg-file/46131/36.
In your app.scss file, add the following code:
ion-icon {
&[class*="appname-"] {
// Instead of using the font-based icons
// We're applying SVG masks
mask-size: contain;
mask-position: 50% 50%;
mask-repeat: no-repeat;
background: currentColor;
width: 1em;
height: 1em;
}
// custom icons
&[class*="appname-customicon1"] {
mask-image: url(../assets/img/customicon1.svg);
}
&[class*="appname-customicon2"] {
mask-image: url(../assets/img/customicon2.svg);
}
&[class*="appname-customicon3"] {
mask-image: url(../assets/img/customicon3.svg);
}
}
Then in your templates, you can use the following HTML to create the icon:
<ion-icon name="appname-customicon"></ion-icon>
This is far less complicated than using the font-based methods. As long as you're not adding hundreds of icons you should be okay with this method. However each image is sent as a separate request, where as with the font methods all the images are contained in one file, so it would be a little more efficient.

If you want to use custom fonts in ionic 2+ you can do it with following.
Step 01:
Have/create custom font SVG files using tools such as XD.
Go to awesome online tool https://icomoon.io to generate font icons out of your SVG files. It's free tool and very good, I am using it for a while.
Download your custom font file.
Your file will look like something below.
[class^="icon-"], [class*=" icon-"] {
font-family: 'icomoon' !important;
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
}
replace above code with :
[class^="icon-"],
[class*=" icon-"],
[class^="ion-ios-icon"],
[class*="ion-ios-icon"],
[class^="ion-md-icon"],
[class*="ion-md-icon"]{
#extend .ion;
font-family: 'icomoon' !important;
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
}
Step 02:
We can use SASS #mixing for repetitive work
#mixin makeIcon($arg, $val) {
.ion-ios-#{$arg}:before ,
.ion-ios-#{$arg}-circle:before ,
.ion-ios-#{$arg}-circle-outline:before ,
.ion-ios-#{$arg}-outline:before ,
.ion-md-#{$arg}:before ,
.ion-md-#{$arg}-circle:before ,
.ion-md-#{$arg}-circle-outline:before ,
.ion-md-#{$arg}-outline:before {
content: $val;
font-size: 26px;
}
}
we can use our sass mixing in our sass file like :
#include makeIcon(icon-new-home, '\e911')
Step 03
Use it like
<ion-tabs class="footer-tabs" [selectedIndex]="mySelectedIndex">
<ion-tab [root]="tab1Root" tabIcon="home"></ion-tab>
<ion-tab [root]="tab2Root" tabIcon="icon-new-home"></ion-tab>
</ion-tabs>
and its even support android ripple effect, which kinda looks cool
[Updated] 30 Nov 2017
#ionic/app-scripts : 3.1.2
Ionic Framework : ionic-angular 3.9.2
For Ionic 3.1.2
You need to add #import "ionicons"; inside your /src/theme/variables.scss file which will fix below error
"[class^="icon-"]" failed to #extend ".ion". The selector ".ion" was not found. Use "#extend .ion !optional"
if the extend should be able to fail.

With the current Ionic 3.3.0 you can use the solution from Anjum, but you have to change
#import "ionic.ionicons";
to
#import "ionicons";
in the src/theme/variables.scss file.
Found this solution at:
https://github.com/yannbf/ionicCustomIconsSample/blob/master/src/theme/variables.scss

Been trying to implement Anjum Nawab shaikh answer on top with the icons sass sheet from icomoon.
I have been able to get it working with version 2.2.2.
In the www/fonts of the project I had added the icomoon files:
icomoon.svg
icomoon.ttf
icomoon.woff
icomoon.eot
icomoon.scss
In icomoon.scss I added the following scss:
#font-face {
font-family: 'icomoon';
src: url('../fonts/icomoon.eot?tclihz');
src: url('../fonts/icomoon.eot?tclihz#iefix') format('embedded-opentype'),
url('../fonts/icomoon.ttf?tclihz') format('truetype'),
url('../fonts/icomoon.woff?tclihz') format('woff'),
url('../fonts/icomoon.svg?tclihz#icomoon') format('svg');
font-weight: normal;
font-style: normal;
}
[class^="icon-"],
[class*=" icon-"],
[class^="ion-ios-icon"],
[class*="ion-ios-icon"],
[class^="ion-md-icon"],
[class*="ion-md-icon"]{
/* Didn't feel the need to #extend since this just adds to already existing .ion
code which I believe is replaced to just ion-icon tag selector in
www/assets/fonts/ionicons.scss */
font-family: "Ionicons", "icomoon" !important; //So just add this
}
//Mixin
#mixin makeIcon($arg, $val) {
.ion-ios-#{$arg}:before ,
.ion-ios-#{$arg}-circle:before ,
.ion-ios-#{$arg}-circle-outline:before ,
.ion-ios-#{$arg}-outline:before ,
.ion-md-#{$arg}:before ,
.ion-md-#{$arg}-circle:before ,
.ion-md-#{$arg}-circle-outline:before ,
.ion-md-#{$arg}-outline:before {
//important to overwrite ionic icons with your own icons
content: $val !important;
font-size: 26px;
}
}
//Adding Icons
#include makeIcon(email, '\e900');
...
Then I did an import to the variables.scss
#import "../www/fonts/icomoon";
Now we can add this to the html template:
<ion-icon name="email"></ion-icon>

Before starting : make sure that you have every svg file you need.
Now just go here : http://fontello.com/
That tool will generate your icon font and the CSS needed with. It is pretty intuitive, just use it, download, and copy your font wherever you want in your www folder but keep the same file structure. To finish, just integrate your CSS file in your index.html file and you're done!
I hope it will solve your issue! ;-)

According to ionic team:
Hey there!
Right now it's limited to using ionicons, since underneath it's rendering an ion-icon, and thats handling the platform differences. You could open an issue and we could discuss adding this feature there
You can see all answers in here:
https://forum.ionicframework.com/t/anyway-to-custom-the-tabbars-icon-with-my-own-svg-file/46131/16
I also find this:
https://www.npmjs.com/package/ionic2-custom-icons ,
but do not seems a clever solution (I prefer to wait for a solution of Ionic team).
The best scenario for this is use old way, by creating a class on a scss file.

For add custom icons I use in my scss file:
.ion-ios-MYICON:before,
.ion-ios-MYICON-circle:before,
.ion-ios-MYICON-circle-outline:before,
.ion-ios-MYICON-outline:before,
.ion-md-MYICON:before,
.ion-md-MYICON-circle:before,
.ion-md-MYICON-circle-outline:before,
.ion-md-MYICON-outline:before {
#extend .ion;
}
.ion-ios-MYICON:before,
.ion-ios-MYICON-outline:before,
.ion-md-MYICON:before,
.ion-md-MYICON-outline:before {
content: 'your-custom-image';
}
Then in your HTML code:
<ion-icon name="MYICON"></ion-icon>

I think this step-by-step by GerritErpenstein is very intuitive, it works pretty good for me. My Ionic version is 2.2.2. Literally, you use a sentence like this and it's done:
<custom-icon set="star" name="iconostar"></custom-icon>
https://github.com/GerritErpenstein/ionic2-custom-icons

Create Icon
ion-icon {
&[class*="custom-"] {
mask-size: contain;
mask-position: 50% 50%;
mask-repeat: no-repeat;
background: currentColor;
width: 0.8em;
height: 0.8em;
}
&[class*="custom-rupee"] {
color: yellow;
mask-image: url(../../assets/Images/rupee.svg);
}
&[class*="custom-ballon"] {
mask-image: url(../../assets/ballon.svg);
}
&[class*="custom-mouse"] {
mask-image: url(../../assets/mouse.svg);
}
}
And to use them
<ion-icon name="custom-rupee"></ion-icon>
<ion-icon name="custom-mouse"></ion-icon>
<ion-icon name="custom-ballon"></ion-icon>

If ionic way is not working for you, you can work with the angular way. Use this package: https://www.npmjs.com/package/angular-svg-icon.
Sample Code for ionic usage:
<svg-icon src="/assets/icons/activity.svg"></svg-icon>

Following is the recommended way to display external svg icons using ion-icon:
To use a custom SVG, provide its url in the src attribute to request the external SVG file. The src attribute works the same as in that the url must be accessible from the webpage that's making a request for the image. Additionally, the external file can only be a valid svg and does not allow scripts or events within the svg element.
<ion-icon src="assets/icons/custom_icon.svg"></ion-icon>
Reference: https://ionic.io/ionicons/usage

Related

change font in ionic input

In an ionic app, I am trying to change the font family of input.
in global.css i'm specifing the global font
* {
font-family: 'FFMalmoom' !important;
}
I want the ion-input text in specific page to take another family
i tried:
ion-input {
font-family: 'verdana' !important;
}
ion-input {
--ion-font-family: 'verdana' !important;
}
with no success , It still takes 'FFMalmoom'.
Instead of specifying the global font in the global.scss move it to the :root selector in the variables.scss file with the --ion-font-family css variable
:root {
--ion-font-family: 'FFMalmoom';
}
After that the font will still be applied globally as ionic uses this as the base font for the entire app. You can then set the ion-input font-family as you normally would with
ion-input{
font-family: 'verdana';
}

Magento 2 - Layered Navigation Swatches Styling

I am using Magento 2.4.5 and would like to make edit css of the icons in the layered navigation, need them smaller and put them in rows of 6.
I cannot find where I need to add/edit the css files for this part of the website. I tried Magento_Swatches\web\css\source_module.less but no result.
Any help would be appreciated.
Thank you
If you are using the default Luma theme:
Note: First, you need to check the template file of the CSS source used.
You need to edit the CSS file: swatches.css or custom CSS if you have created one. Getting the correct element may it can give you a correct catch.
Could you adjust the width and height of the swatch div? Please remember to specify! an important rule in CSS.
.swatches-globo .swatch--gl .ul-swatches-list li:not(ul.ul-globo-dropdown-option li), .globo-swatch-product-detail .swatch--gl ul.value li:not(ul.ul-globo-dropdown-option li) {
display: block;
float: left;
margin: 0 10px 10px 0!important;
}
Also,
.swatches-globol .swatch--gl li .globo-size-medium, .globo-swatch-product-detail .globo-detail-size-medium {
width: 35px;
height: 35px;
}
OR
.swatch-option.color {
min-width: 25px;
height: 25px;
}
Thanks

Display tabs in multiple rows [duplicate]

I commonly have 10+ tabs open per editor window which makes it tedious to scroll back and forth (or use ctrl+tab) to find the file I want.
Is there any way to have the tabs wrap?
Similar to Atom's multirow-tabs.
Update: Looks like it is a work in progress.
UPDATE Feb 2021: In-built support for tabs-wrapping in VSCode v1.53.0+
Just set the workbench.editor.wrapTabs to true in the settings.
I still use my configuration mentioned below to make tabs smaller as per my usage.
UPDATED 28 March 2020 for VSCode v1.43.2
Fixed CSS for tab-close button
Added CSS for smaller bread-crumbs and acion-bar (at the right of tab-bar)
I do the following for multirow tabs in visual-studio-code (until there is official support or an easier solution):
STEP 1: Install the extension VSCode Custom CSS. (Check out the extension page for proper installation instruction. It's a bit of a hack as VSCode does not officially support altering internal CSS.)
STEP 2: Create a CSS file (say, "/home/user/vscode/custom.css") and add the following contents:
/* Following CSS to wrap the tab-bar into multiple rows: */
.tabs-and-actions-container > .monaco-scrollable-element {
height: auto !important;
}
.tabs-and-actions-container > .monaco-scrollable-element > .tabs-container {
height: auto !important;
flex-wrap: wrap;
}
/* Following CSS to make the tabs thinner/smaller (so that they take lesser vertical space): */
.monaco-workbench .part.editor > .content .editor-group-container > .title .tabs-container > .tab {
height: 25px;
padding-left: 4px;
font-size: 0.8em; /* smaller font-size for tab icons and label */
}
.monaco-workbench .part.editor > .content .editor-group-container > .title .tabs-container > .tab .label-name {
font-size: inherit !important; /* inherit updated font-size for label */
}
/* Following CSS for smaller close button on tabs: */
.monaco-workbench .part.editor>.content .editor-group-container>.title .tabs-container>.tab>.tab-close {
width: 20px;
}
.monaco-workbench .part.editor>.content .editor-group-container>.title .tabs-container>.tab>.tab-close .action-label {
height: 12px;
width: 12px;
background-size: 12px;
}
.monaco-workbench .part.editor>.content .editor-group-container.active>.title .tabs-container>.tab>.tab-close .action-label.codicon {
font-size: 12px;
}
/* OPTIONAL: Following CSS for smaller breadcrumbs (below tab-bar) */
.monaco-breadcrumbs {
font-size:0.65em;
opacity: 0.8;
height:18px !important;
}
.tabs-breadcrumbs .breadcrumbs-control {
height: 18px !important;
}
.monaco-workbench .symbol-icon.block {
height: 8px;
width: 8px;
min-height: 8px;
min-width: 14px;
background-position: 50%;
background-size: contain;
}
.breadcrumbs-control .monaco-breadcrumb-item:before {
min-width: 12px !important;
height: 12px !important;
background-size: contain !important;
}
/* OPTIONAL: Following CSS for smaller action-bar (beside the tab-bar) with menu, split, etc. */
.monaco-workbench .part.editor>.content .editor-group-container>.title .editor-actions {
height: 20px;
padding:0;
}
.monaco-workbench .part.editor>.content .editor-group-container>.title .editor-actions .action-label, .monaco-workbench .part.editor>.content .editor-group-container>.title .title-actions .action-label {
height: 20px;
line-height: 20px;
min-width: 14px;
background-size: 8px;
}
.tabs-and-actions-container > .editor-actions > .monaco-toolbar > .monaco-action-bar > .actions-container {
max-width:60px;
flex-wrap:wrap;
}
STEP 3: Point the extension to your custom CSS. Open the VSCode settings.json [Ctrl+Shift+P > "Open Settings(JSON)"] and add the following lines (with your path to custom.css file):
"vscode_custom_css.imports": [
"file:///home/user/vscode/custom.css"
],
"vscode_custom_css.policy": true
STEP 4: Make sure you have gone through the VSCode Custom CSS extension's readme and enabled it properly. You may have to reload VSCode. Also, edit the CSS as per your preferences!
CREDIT: This solution (link to extension and the CSS to wrap tab-bar into multi-lines) was originally posted by Steven Laidlaw in this Github thread. I just extended the CSS for smaller tabs.
UPDATE: Version 1.53 includes wrap tabs!
The new "Wrap Tabs" setting is a checkbox under File > Preferences > Settings > Workbench > Editor Management.
Alternatively, you can set paste the following into your settings.json: "workbench.editor.wrapTabs": true
Significant progress has been made on this issue Allow tabs to wrap to multi-line and the feature is now in the Insiders' Build (and presumably in v1.53 Stable as it works well in my testing):
As seen in the demo, you can even drag tabs from one row to another. There is currently no limit on the number of rows until the editor itself gets too small.
You enable this functionality with
workbench.editor.wrapTabs: true or
Workbench > Editor: Wrap Tabs in the Settings gui.
A couple of notes from testing tab wrapping:
make sure you have configured workbench.editor.tabSizing: fit (this will make the last tab fill the entire row for a more homogeneous look when tabs wrap) [ed. note: you can still use shrink, it just doesn't look as nice]
if the space for the editor or editor toolbar becomes too small, wrapping turns off automatically and turns on again when the size get's larger
you can still drag and drop tabs around even when they wrap
you can still pin a tab and it shows pinned in the beginning of the tabs
when tabs wrap, the tab.border color is not only applied to the right of each tab but also below to separate tabs from each other
Also, depending on your color theme, consider modifying these settings:
"workbench.colorCustomizations": {
"tab.border": "#fff6",
"titleBar.border": "#fff6",
"editorGroupHeader.tabsBorder": "#647c64",
}
to set off the borders of each tab.
There is some hope for a second row of tabs - albeit with pinned tabs but still sounds pretty useful. See Pinned tabs: show them in a secondary tab row above others. Added to the Backlog.
By the way, pinned tabs are coming to v1.46. More on their functionality: v1.46 release notes: pinned tabs
Since multirow tabs are still not officialy supported in VSCode, I wanted to bring a feature request to your attention that I just posted on their github.
Instead of always wrapping tabs to a new row I propose to have them laid out on rows that are completely independent from each other. The user decides, they can mix short rows with long rows that still require scrolling. See the details here:
github.com/microsoft/vscode/issues/80510
My proposed solution certainly requires more work than unceremoniously wrapping tabs to a new row but in return it lets the user organize their tabs in a way that could increase productivity.
I just played with the vscode developer tools console, and looks like this CSS will be enough to do that if incorporated with an extension:
.tabs-and-actions-container .monaco-scrollable-element {
height: auto;
}
.tabs-and-actions-container .monaco-scrollable-element .tabs-container {
flex-wrap: wrap; flex: 1 1 auto;
height: auto;
}
You can add this code to file:///C:/Users/[username]/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.main.css file to use it until your application updates.
Note: When you add this to workbench.main.css file, VSCode will alert that the integrity of VScode is corrupted, ignore that message. VSCode will function as before because it's a CSS change (if any javascript doesn't use some positions of the tabs, or something else).
Otherwise as #Bene said, this is a restricted area by VSCode development team. They say:
Restrictions
There are certain restrictions we impose upon extensions.
Here are the restrictions and their purposes.
No DOM Access
Extensions have no access to the DOM of VS Code UI. You
cannot write an extension that applies custom CSS to VS Code or adds
an HTML element to VS Code UI.
At VS Code, we're continually trying to optimize use of the underlying
web technologies to deliver an always available, highly responsive
editor and we will continue to tune our use of the DOM as these
technologies and our product evolve. To ensure that extensions cannot
interfere with the stability and performance of VS Code, and that we
can continue to improve the DOM of VS Code without breaking existing
extensions, we run extensions in an Extension Host process and prevent
direct access to the DOM.
# https://code.visualstudio.com/api/extension-capabilities/overview#no-dom-access
I have found/developed a solution to display pinned tabs in their own row.. It's an addition to what people might be using already, not the answer to this thread per se.
Original reply on github: https://github.com/microsoft/vscode/issues/98160#issuecomment-989276052
vscode v1.62.3
extension: Custom CSS and JS Loader v6.0.2
settings.json
{
"workbench.editor.wrapTabs": true,
"git.decorations.enabled": false,
"workbench.editor.decorations.badges": false,
"workbench.editor.decorations.colors": false,
"vscode_custom_css.imports": ["file:///C:/temp/VScode/custom.css"],
"vscode_custom_css.policy": true
}
p.s. In config above I also disabled some git stuff from tabs to make them more readable.. not sure if it affects other places, use with caution.
custom.css
.tabs-container {
display: flex !important;
flex-wrap: wrap !important;
height: auto !important;
}
.tabs-container::before,
.tabs-container::after {
content: "" !important;
width: 100% !important;
order: 1 !important;
}
.tab {
display: flex !important;
}
.tab:not(.sticky) {
order: 1 !important;
}
Result (gif):

Ionic 4: How to overflow div from Ionic Header or Toolbar?

I want create a drop down menu or popover within ionic toolbar. I tried with several ways but can not solve. Its always hidden like bellow,
I trying css like bellow,
.popover{
border: 1px solid black;
height: 350px;
width: 150px;
position: absolute;
z-index: 99999999;
background: yellow;
}
ion-header{
contain: none;
}
ion-toolbar{
contain: none;
}
Please give me a suggestion or an alternative idea. Please do not give any predictive answer if you are not familiar with ionic.
I don't know about Ionic 4 but on Ionic 5, a solution would be this when you debug on the console :
ion-toolbar {
contain: none;
.toolbar-container {
overflow: visible;
contain: none;
}
}
However, the .toolbar-container is an element in the shadow dom of the <ion-toolbar> component and its overflow and contain properties are not css variables and there is no part attribute on this element neither. So there is actually no way to override those properties.
I'm considering using this package, but for me it seems like overkill to use js and timeout for setting a pretty simple style... :
https://www.npmjs.com/package/shadow-dom-inject-styles
I had a similar problem when I had to make a searchbar overflow underneath the header (design thing). I was struggling a while and it popped in place suddenly when I place the searchbar outside of the toolbar and gave it position absolute:
<ion-head>
<ion-toolbar>
<!-- My stuff here -->
</ion-toolbar>
<ion-searchbar></ion-searchbar>
<ion-header>
My css looks like this:
ion-toolbar {
display: flex; // I need this for something else, but maybe has an influence
}
ion-searchbar {
padding: 0 1em .5em 1em;
transform: translateY(-50%);
z-index: 99999;
position: absolute;
}
Hope it helps somebody.
In case anyone is still looking for the solution. Here is how I managed to fixed it in react. It's a bit hacky solution, but most likely the only one ATM.
First we need to style the toolbar (pass a className or style to component:
.your-toolbar-classname {
overflow: visible!important;
contain: none!important;
}
Then we have to also style the shadow-root parts. Se we can use the useEffect after the header is mounted and set the style
// Header.tsx
...
useEffect(() => {
const style = document.createElement('style');
style.innerHTML =
'.toolbar-container { overflow: visible!important; contain: none!important; }';
toolbarRef.current.shadowRoot.appendChild(style);
}, []);
...
Just use ion-menu, its a build in ionic component
https://ionicframework.com/docs/api/menu
There is also ion-popover
You should look at the ionic docs before posting on stack

Multirow Tabs for VSCode

I commonly have 10+ tabs open per editor window which makes it tedious to scroll back and forth (or use ctrl+tab) to find the file I want.
Is there any way to have the tabs wrap?
Similar to Atom's multirow-tabs.
Update: Looks like it is a work in progress.
UPDATE Feb 2021: In-built support for tabs-wrapping in VSCode v1.53.0+
Just set the workbench.editor.wrapTabs to true in the settings.
I still use my configuration mentioned below to make tabs smaller as per my usage.
UPDATED 28 March 2020 for VSCode v1.43.2
Fixed CSS for tab-close button
Added CSS for smaller bread-crumbs and acion-bar (at the right of tab-bar)
I do the following for multirow tabs in visual-studio-code (until there is official support or an easier solution):
STEP 1: Install the extension VSCode Custom CSS. (Check out the extension page for proper installation instruction. It's a bit of a hack as VSCode does not officially support altering internal CSS.)
STEP 2: Create a CSS file (say, "/home/user/vscode/custom.css") and add the following contents:
/* Following CSS to wrap the tab-bar into multiple rows: */
.tabs-and-actions-container > .monaco-scrollable-element {
height: auto !important;
}
.tabs-and-actions-container > .monaco-scrollable-element > .tabs-container {
height: auto !important;
flex-wrap: wrap;
}
/* Following CSS to make the tabs thinner/smaller (so that they take lesser vertical space): */
.monaco-workbench .part.editor > .content .editor-group-container > .title .tabs-container > .tab {
height: 25px;
padding-left: 4px;
font-size: 0.8em; /* smaller font-size for tab icons and label */
}
.monaco-workbench .part.editor > .content .editor-group-container > .title .tabs-container > .tab .label-name {
font-size: inherit !important; /* inherit updated font-size for label */
}
/* Following CSS for smaller close button on tabs: */
.monaco-workbench .part.editor>.content .editor-group-container>.title .tabs-container>.tab>.tab-close {
width: 20px;
}
.monaco-workbench .part.editor>.content .editor-group-container>.title .tabs-container>.tab>.tab-close .action-label {
height: 12px;
width: 12px;
background-size: 12px;
}
.monaco-workbench .part.editor>.content .editor-group-container.active>.title .tabs-container>.tab>.tab-close .action-label.codicon {
font-size: 12px;
}
/* OPTIONAL: Following CSS for smaller breadcrumbs (below tab-bar) */
.monaco-breadcrumbs {
font-size:0.65em;
opacity: 0.8;
height:18px !important;
}
.tabs-breadcrumbs .breadcrumbs-control {
height: 18px !important;
}
.monaco-workbench .symbol-icon.block {
height: 8px;
width: 8px;
min-height: 8px;
min-width: 14px;
background-position: 50%;
background-size: contain;
}
.breadcrumbs-control .monaco-breadcrumb-item:before {
min-width: 12px !important;
height: 12px !important;
background-size: contain !important;
}
/* OPTIONAL: Following CSS for smaller action-bar (beside the tab-bar) with menu, split, etc. */
.monaco-workbench .part.editor>.content .editor-group-container>.title .editor-actions {
height: 20px;
padding:0;
}
.monaco-workbench .part.editor>.content .editor-group-container>.title .editor-actions .action-label, .monaco-workbench .part.editor>.content .editor-group-container>.title .title-actions .action-label {
height: 20px;
line-height: 20px;
min-width: 14px;
background-size: 8px;
}
.tabs-and-actions-container > .editor-actions > .monaco-toolbar > .monaco-action-bar > .actions-container {
max-width:60px;
flex-wrap:wrap;
}
STEP 3: Point the extension to your custom CSS. Open the VSCode settings.json [Ctrl+Shift+P > "Open Settings(JSON)"] and add the following lines (with your path to custom.css file):
"vscode_custom_css.imports": [
"file:///home/user/vscode/custom.css"
],
"vscode_custom_css.policy": true
STEP 4: Make sure you have gone through the VSCode Custom CSS extension's readme and enabled it properly. You may have to reload VSCode. Also, edit the CSS as per your preferences!
CREDIT: This solution (link to extension and the CSS to wrap tab-bar into multi-lines) was originally posted by Steven Laidlaw in this Github thread. I just extended the CSS for smaller tabs.
UPDATE: Version 1.53 includes wrap tabs!
The new "Wrap Tabs" setting is a checkbox under File > Preferences > Settings > Workbench > Editor Management.
Alternatively, you can set paste the following into your settings.json: "workbench.editor.wrapTabs": true
Significant progress has been made on this issue Allow tabs to wrap to multi-line and the feature is now in the Insiders' Build (and presumably in v1.53 Stable as it works well in my testing):
As seen in the demo, you can even drag tabs from one row to another. There is currently no limit on the number of rows until the editor itself gets too small.
You enable this functionality with
workbench.editor.wrapTabs: true or
Workbench > Editor: Wrap Tabs in the Settings gui.
A couple of notes from testing tab wrapping:
make sure you have configured workbench.editor.tabSizing: fit (this will make the last tab fill the entire row for a more homogeneous look when tabs wrap) [ed. note: you can still use shrink, it just doesn't look as nice]
if the space for the editor or editor toolbar becomes too small, wrapping turns off automatically and turns on again when the size get's larger
you can still drag and drop tabs around even when they wrap
you can still pin a tab and it shows pinned in the beginning of the tabs
when tabs wrap, the tab.border color is not only applied to the right of each tab but also below to separate tabs from each other
Also, depending on your color theme, consider modifying these settings:
"workbench.colorCustomizations": {
"tab.border": "#fff6",
"titleBar.border": "#fff6",
"editorGroupHeader.tabsBorder": "#647c64",
}
to set off the borders of each tab.
There is some hope for a second row of tabs - albeit with pinned tabs but still sounds pretty useful. See Pinned tabs: show them in a secondary tab row above others. Added to the Backlog.
By the way, pinned tabs are coming to v1.46. More on their functionality: v1.46 release notes: pinned tabs
Since multirow tabs are still not officialy supported in VSCode, I wanted to bring a feature request to your attention that I just posted on their github.
Instead of always wrapping tabs to a new row I propose to have them laid out on rows that are completely independent from each other. The user decides, they can mix short rows with long rows that still require scrolling. See the details here:
github.com/microsoft/vscode/issues/80510
My proposed solution certainly requires more work than unceremoniously wrapping tabs to a new row but in return it lets the user organize their tabs in a way that could increase productivity.
I just played with the vscode developer tools console, and looks like this CSS will be enough to do that if incorporated with an extension:
.tabs-and-actions-container .monaco-scrollable-element {
height: auto;
}
.tabs-and-actions-container .monaco-scrollable-element .tabs-container {
flex-wrap: wrap; flex: 1 1 auto;
height: auto;
}
You can add this code to file:///C:/Users/[username]/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.main.css file to use it until your application updates.
Note: When you add this to workbench.main.css file, VSCode will alert that the integrity of VScode is corrupted, ignore that message. VSCode will function as before because it's a CSS change (if any javascript doesn't use some positions of the tabs, or something else).
Otherwise as #Bene said, this is a restricted area by VSCode development team. They say:
Restrictions
There are certain restrictions we impose upon extensions.
Here are the restrictions and their purposes.
No DOM Access
Extensions have no access to the DOM of VS Code UI. You
cannot write an extension that applies custom CSS to VS Code or adds
an HTML element to VS Code UI.
At VS Code, we're continually trying to optimize use of the underlying
web technologies to deliver an always available, highly responsive
editor and we will continue to tune our use of the DOM as these
technologies and our product evolve. To ensure that extensions cannot
interfere with the stability and performance of VS Code, and that we
can continue to improve the DOM of VS Code without breaking existing
extensions, we run extensions in an Extension Host process and prevent
direct access to the DOM.
# https://code.visualstudio.com/api/extension-capabilities/overview#no-dom-access
I have found/developed a solution to display pinned tabs in their own row.. It's an addition to what people might be using already, not the answer to this thread per se.
Original reply on github: https://github.com/microsoft/vscode/issues/98160#issuecomment-989276052
vscode v1.62.3
extension: Custom CSS and JS Loader v6.0.2
settings.json
{
"workbench.editor.wrapTabs": true,
"git.decorations.enabled": false,
"workbench.editor.decorations.badges": false,
"workbench.editor.decorations.colors": false,
"vscode_custom_css.imports": ["file:///C:/temp/VScode/custom.css"],
"vscode_custom_css.policy": true
}
p.s. In config above I also disabled some git stuff from tabs to make them more readable.. not sure if it affects other places, use with caution.
custom.css
.tabs-container {
display: flex !important;
flex-wrap: wrap !important;
height: auto !important;
}
.tabs-container::before,
.tabs-container::after {
content: "" !important;
width: 100% !important;
order: 1 !important;
}
.tab {
display: flex !important;
}
.tab:not(.sticky) {
order: 1 !important;
}
Result (gif):