How to position floating ion-label inside ion-text-area? - css

In my Ionic 5 app, I am displaying a text-area with a floating label like so:
Then when the user clicks on the <ion-text-area>, it appears like this:
Can someone please tell me how I can initially display the floating label nicely inside the text-area?
The label should be within the radius of the text-area when the page loads up.
Here is my current HTML & CSS:
<ion-item lines="none">
<ion-label position="floating">
Please describe your issue to {{ mechanicToContact.name }} here
</ion-label>
<ion-textarea
style="border-radius:30px;
background: #6E73AA;
padding: 5px";
color="primary"
rows="6"
cols="20"
required
minlength="15">
</ion-textarea>
</ion-item>

Just place your ion-label in "front" of your ion-textarea using z-index css attribute.
I suggest you do something like this to achieve relatively what you are looking for.
component.html
<ion-item lines="none">
<ion-label position="floating" class="position-label-inside">
Please describe your issue to {{ mechanicToContact.name }} here
</ion-label>
<ion-textarea
style="border-radius:30px;
background: #6E73AA;
padding: 5px;"
color="primary"
rows="6"
cols="20"
required
minlength="15">
</ion-textarea>
</ion-item>
component.scss
#keyframes slide-out {
from {padding-left: 15px}
to {padding-left: 0}
}
.position-label-inside {
padding-left: 15px;
z-index: 1;
}
ion-item.item-has-focus {
.position-label-inside {
animation-name: slide-out;
animation-duration: 1s;
padding-left: 0!important;
}
}
ion-textarea {
z-index: 0;
}

Related

How to hover ion-card inside ion-list

I have an ion-list which have a button and card inside it, now I want to change the color of the button and card on hover but can't find a way to do it.
Here is my code. Thanks in advance
Html
<div [hidden] = hidden >
<ion-list>
<ion-card >
<button inset = true *ngFor="let item of items" (click)="open($event, item.name)" >
<ion-card>
<h2> <b>{{ item.name }} </b> </h2>
<p> Recommended for</p>
{{item.Description}}
</ion-card>
<br>
<br>
</button>
</ion-card>
</ion-list>
</div>
CSS
ion-card{
display: flex;
flex-direction: column;
width: 100% !important;
margin: 0 !important;
background-color:white;
box-shadow: none;
}
button.item:hover a{
background-color: slategray;
box-shadow: inset 0px 0px 0px 1px red;
}
First of all u can't hover on device but u can attach click events for that u need to use ngStyle in ur components to change color or show if its clicked.
<div [hidden] = hidden >
<ion-list *ngFor="let item of items">
<ion-card >
<ion-button (click)="open($event, item.name)" fill="clear" >
<ion-icon slot="icon-only" [name]="buttonIcon" [ngStyle]="{'color':color1}"></ion-icon>
</ion-button>
<ion-card>
<h2> <b>{{ item.name }} </b> </h2>
<p> Recommended for</p>
{{item.Description}}
</ion-card>
<br>
<br>
</button>
</ion-card>
</ion-list>
</div>
inside ur TS
buttonIcon: string = "md-add";
color1: string = "black";
open(event,item){
this.buttonIcon = "done-all"; // icon change name if u want to change icon too
this.color1 ="red"; // any color u want it to change to
//rest of your code
}
U can use the same ngstyle on ur ion card as well to change color.
U can also use ion-ripple-effect to show some sort of click feedback on cards.

ionic 3 ion-input inside ion-item height issues

i am building a website and the form has input with label. They seems to have too my height and i am unable to figure out how to reduce it. the code looks like
<ion-grid>
<ion-row>
<ion-col text-right><ion-item no-lines><ion-label class="fa-labels">Name</ion-label><ion-input placeholder="Infrastructure Information" value="Infrastructure Information"></ion-input></ion-item></ion-col>
<ion-col><ion-item no-lines><ion-label class="fa-labels">Close Date</ion-label><ion-input value="7/15/17"></ion-input></ion-item></ion-col>
</ion-row>
<ion-row>
<ion-col text-right><ion-item no-lines><ion-label class="fa-labels">Account</ion-label><ion-input value="Net-World Technologies"></ion-input></ion-item></ion-col>
<ion-col><ion-item no-lines><ion-label class="fa-labels">Status</ion-label><ion-input value="Open"></ion-input></ion-item></ion-col>
</ion-row>
</ion-grid>
applied css
ion-input {
border: 0.5px solid #BCC0C2;
margin: 0px;
padding:0px;
}
doing a padding or margin didnt help to 0px.
Try this:
<ion-input class="ioninput"> <ion-input>
And in CSS:
.ioninput{
input{
height:xx px;
}
}
If I am understanding the docs correctly, you need to style using classes and not by selecting elements themselves. So...
<ion-input class="input" ...></ion-input> and .input { padding: 0; margin: 0; }

Remove tiny scroll bar - Ionic 3

You can see that there is a tiny scroll bar as shown below.Can you tell me how to remove that? This is Ionic 3 app. I have tried many ways.But no luck yet.
Please see how bad it is on the device :(
This on the browser:
.sass
.height-70 {
height: 70px;
overflow: hidden;
}
.html
<ion-content padding>
<ion-grid>
<ion-row>
<ion-col class="height-70" col-12>
<ion-content>
<button ion-button icon-left full (click)="loginWithLinkedin()" class="background-color-linkedin"><ion-icon name="logo-linkedin" class="margin-top-minus-4"></ion-icon><span>Continue with Linkedin</span></button>
</ion-content>
</ion-col>
</ion-row>
</ion-grid>
</ion-content>
Chrome css(run time): below padding:16px is the problem.But how can I remove it? Because I need padding too.Any workaround?
.scroll-content {
overflow-y: hidden;
}
If you use ion-content inside ion-col it will add some properties from scroll-content. Replace ion-content with div and manually add all the css properties you want to your div.
Try like this file app.scss under /src/app/
[scrollbar-y-auto] .scroll-content {
overflow-y: false !important;
}
and
Your code :
<ion-content scrollbar-y-auto>
Not tested Check and let me know
Try out the following,
<ion-content overflow-scroll="false">
1.bounce,
<ion-content no-bounce></ion-content>
2.
.content > .scroll-content::before {
bottom: 0;
}
.content > .scroll-content::after {
top: 0;
}
3.
.scroll-content {
overflow-y: auto !important;
}
4.
<ion-content>
<div ion-fixed>
</div>
</ion-content>
What I have experienced is sometimes you see scrollbar in browser but not on device. I would suggest to you to verify the same in device or try chrome device emulator in dev tools by pressing Ctrl+Shift+M.

How to have an Ionic >=2 scrollable ion-list under fixed search bar

I have an Ionic >=2 application where I would like to have 2 or 3 fixed rows at the top of the page, and then have the rest of the page as a scrollable list (and later I want it to be virtual, but just want to get the simple list working forst).
As a simplified example, I have the following plunk. The markup repeated here is..
<ion-header>
<ion-navbar>
<ion-title>{{ appName }}</ion-title>
</ion-navbar>
</ion-header>
<ion-content scroll=false>
<ion-grid>
<!-- Row 1 fixed at top -->
<ion-row>
<ion-col>
<ion-searchbar></ion-searchbar>
</ion-col>
<!-- Other cols -->
</ion-row>
<!-- Row 2 Scrollable list -->
<ion-row>
<ion-col>
<ion-list>
<ion-item *ngFor="let item of data">
<div>{{item}}</div>
</ion-item>
</ion-list >
</ion-col>
</ion-row>
</ion-grid>
</ion-content>
The problem is the search bar also scrolls with the list, whereas I would like this to always remain visible at the top of the page.
Does anyone know why I have the search bar also scrolling when this is in a completely separate row to the ion-list? Should I be using an ion-grid in this way?
Thanks in advance for any help!
ion-content does not have scroll input property to disable it.
If you need to have searchbar always visible, I suggest you place it in a toolbar.
<ion-header>
<ion-navbar>
<ion-title>{{ appName }}</ion-title>
</ion-navbar>
<ion-toolbar>
<ion-searchbar></ion-searchbar>
</ion-toolbar>
</ion-header>
Or use ion-scroll with a fixed height.
<ion-grid>
<!-- Row 2 Scrollable list -->
<ion-row>
<ion-col>
<ion-searchbar></ion-searchbar>
</ion-col>
</ion-row>
<ion-row>
<ion-col>
<ion-scroll style="width:100%;height:100vh" scrollY="true">
<ion-list scroll="true">
<ion-item *ngFor="let item of data">
<div>{{item}}</div>
</ion-item>
</ion-list>
</ion-scroll>
</ion-col>
</ion-row>
</ion-grid>
Sample Plunkr
Update: To answer #JohnDoe's comment.. in order to get scroll list to take the height of rest of the screen use Viewport percentage height to set the height of ion-scroll.
This is how I managed to have a list at the bottom of the page scroll without scrolling the whole page:
HTML
<ion-content>
<div class="table">
<div class="table-row">
<ion-searchbar></ion-searchbar>
</div>
<div class="table-row last-row">
<div class="table-cell cell-content-outer-wrapper">
<div class="cell-content-inner-wrapper">
<div class="cell-content">
<ion-list>
<ion-item *ngFor="let item of data">
<div>{{item}}</div>
</ion-item>
</ion-list>
</div>
</div>
</div>
</div>
</div>
</ion-content>
CSS
.table {
display: table;
width: 100%;
height: 100%;
}
.table-row {
display: table-row;
}
.table-cell {
display: table-cell;
}
.last-row {
height: 100%;
}
.cell-content-outer-wrapper {
height: 100%;
}
.cell-content-inner-wrapper {
height: 100%;
position: relative;
overflow: auto;
}
.cell-content {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
Makes use of lots of divs but it worked for me in ionic 2 and in onsen-ui as well when I was facing the same problem.
I'm using Ionic 5 with Vue. I wanted to have a fixed content at the top of the page with a scrollable list below. This is all I had to do:
<ion-page>
<ion-header :translucent="true">
<ion-toolbar>
<ion-buttons slot="start">
<ion-back-button defaultHref="/"></ion-back-button>
</ion-buttons>
<ion-title>Page title</ion-title>
</ion-toolbar>
</ion-header>
<ion-card>
<ion-card-content>
<!-- Here is the fixed content -->
</ion-card-content>
</ion-card>
<ion-content>
<!-- This content will scroll -->
<ion-list>
<ion-item>
<ion-label>Pokémon Yellow</ion-label>
</ion-item>
<ion-item>
<ion-label>Mega Man X</ion-label>
</ion-item>
<ion-item>
<ion-label>The Legend of Zelda</ion-label>
</ion-item>
<ion-item>
<ion-label>Pac-Man</ion-label>
</ion-item>
<ion-item>
<ion-label>Super Mario World</ion-label>
</ion-item>
</ion-list>
</ion-content>
</ion-page>
The trick was in putting the fixed content between <ion-header> and <ion-content> components.
I've made an npm packge that create this fixed scroll.
You need to install and use the npm package on your project (ionic3)
npm install --save ionic2-fixedscroll-directive
Import the ngFixedScrollDirective module on your page or AppModule
import { NgFixedScrollModule } from 'ionic2-fixedscroll-directive';
#NgModule({
declarations: [
MyPage
],
imports: [
IonicPageModule.forChild(MyPage),
NgFixedScrollModule
],
entryComponents: [
MyPage
]
})
export class MyPageModule {}
Create the SASS CSS to fix the element
your-page {
ion-searchbar {
&.fixed {
#extend .toolbar; //optional
position: fixed;
top: 0;
transition: all 0.5s ease;
&.searchbar-ios {
transform: translateY(calc(#{$navbar-ios-height} + #{$cordova-ios-statusbar-padding}));
}
&.searchbar-md {
transform: translateY(#{$navbar-md-height});
}
&.searchbar-wp {
transform: translateY(#{$navbar-md-height});
}
z-index: 3; //zindex to put it on top of some ionic components
}
}
}
And add the directive to the component or element that you need to fix on top of the page (outside the toolbar)
<YourComponent fixed-scroll></YourComponent>
More info on the directive git repo: https://github.com/joao-gsneto/ionic2-fixedscroll-directive

margin bottom in css with two vertical span elements

I am using ionic and wanted vertical span elements to have a certain distance between.
Here is a demo:
http://play.ionic.io/app/8682286f77a8
<ion-item class="item item-avatar icon-row">
<img src="img/sale_icon.jpg">
<span style="color:#078d00;font-size:22px; margin-bottom: 1opx"> {{ '36,000' }}</span>
<br>
<span style="color:#4b4b4b;font-size:18px"> Sale</span>
</ion-item>
However, margin-bottom is not working at all.
I could use another br between these spans and that works but it create more distance than I really want to.
What does really look wrong with it in above piece of code?
Just add display: inherit; property to span. It will work.
Plus, whenever you add some styling in ionic framework, don't forget to add !important with styling, because elements in ionic directives inherit styling from parent element.
Add display:inline-block to the span. It will make them respect the margin-bottom property.
<ion-item class="item item-avatar icon-row">
<img src="img/sale_icon.jpg">
<span style="color:#078d00;font-size:22px; margin-bottom: 10px;display:inline-block;"> {{ '36,000' }}</span>
<br>
<span style="color:#4b4b4b;font-size:18px;display:inline-block"> Sale</span>
</ion-item>
I've updated your code -
span {
display: list-item;
list-style-type: none;
}
now margin-bottom works well!!
Full Code -
<ion-item class="item item-avatar icon-row">
<img src="img/sale_icon.jpg">
<span style="color:#078d00;font-size:22px; margin-bottom:10px;"> {{ '36,000' }}</span>
<span style="color:#4b4b4b;font-size:18px;"> Sale</span>
</ion-item>
/* CSS */
span {
display: list-item;
list-style-type: none;
}
Working Demo, with display: list-item you don't need to add <br> after the span.

Resources