mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-19 19:57:22 +08:00
fix(label): only show placeholder with floating label when focused (#22958)
fixes #17571
This commit is contained in:
@ -169,3 +169,18 @@
|
|||||||
:host(.has-focus) button {
|
:host(.has-focus) button {
|
||||||
pointer-events: auto;
|
pointer-events: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Item Floating: Placeholder
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// When used with a floating item the placeholder should hide
|
||||||
|
|
||||||
|
:host-context(.item-label-floating.item-has-placeholder:not(.item-has-value)) {
|
||||||
|
transition: opacity 0.15s cubic-bezier(0.4, 0, 0.2, 1);
|
||||||
|
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
:host-context(.item-label-floating.item-has-placeholder:not(.item-has-value).item-has-focus) {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
@ -190,15 +190,6 @@ export class Input implements ComponentInterface {
|
|||||||
*/
|
*/
|
||||||
@Prop({ mutable: true }) value?: string | number | null = '';
|
@Prop({ mutable: true }) value?: string | number | null = '';
|
||||||
|
|
||||||
/**
|
|
||||||
* Update the native input element when the value changes
|
|
||||||
*/
|
|
||||||
@Watch('value')
|
|
||||||
protected valueChanged() {
|
|
||||||
this.emitStyle();
|
|
||||||
this.ionChange.emit({ value: this.value == null ? this.value : this.value.toString() });
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Emitted when a keyboard input occurred.
|
* Emitted when a keyboard input occurred.
|
||||||
*/
|
*/
|
||||||
@ -225,6 +216,23 @@ export class Input implements ComponentInterface {
|
|||||||
*/
|
*/
|
||||||
@Event() ionStyle!: EventEmitter<StyleEventDetail>;
|
@Event() ionStyle!: EventEmitter<StyleEventDetail>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the item classes when the placeholder changes
|
||||||
|
*/
|
||||||
|
@Watch('placeholder')
|
||||||
|
protected placeholderChanged() {
|
||||||
|
this.emitStyle();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the native input element when the value changes
|
||||||
|
*/
|
||||||
|
@Watch('value')
|
||||||
|
protected valueChanged() {
|
||||||
|
this.emitStyle();
|
||||||
|
this.ionChange.emit({ value: this.value == null ? this.value : this.value.toString() });
|
||||||
|
}
|
||||||
|
|
||||||
componentWillLoad() {
|
componentWillLoad() {
|
||||||
this.inheritedAttributes = inheritAttributes(this.el, ['tabindex', 'title']);
|
this.inheritedAttributes = inheritAttributes(this.el, ['tabindex', 'title']);
|
||||||
}
|
}
|
||||||
|
@ -132,11 +132,11 @@
|
|||||||
<ion-label>Right</ion-label>
|
<ion-label>Right</ion-label>
|
||||||
<ion-input class="ion-text-right" value="Narrow input"></ion-input>
|
<ion-input class="ion-text-right" value="Narrow input"></ion-input>
|
||||||
</ion-item>
|
</ion-item>
|
||||||
|
|
||||||
</ion-content>
|
</ion-content>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
document.querySelector('ion-input').addEventListener('ionBlur', (ev) => { console.log(ev)})
|
document.querySelector('ion-input').addEventListener('ionBlur', (ev) => { console.log(ev)});
|
||||||
|
|
||||||
function toggleBoolean(id, prop) {
|
function toggleBoolean(id, prop) {
|
||||||
var el = document.getElementById(id);
|
var el = document.getElementById(id);
|
||||||
|
|
||||||
|
@ -13,27 +13,130 @@
|
|||||||
|
|
||||||
<body>
|
<body>
|
||||||
<ion-app>
|
<ion-app>
|
||||||
|
<ion-header>
|
||||||
|
<ion-toolbar>
|
||||||
|
<ion-title>Input - Spec</ion-title>
|
||||||
|
</ion-toolbar>
|
||||||
|
</ion-header>
|
||||||
<ion-content>
|
<ion-content>
|
||||||
|
<h1>Floating Inputs</h1>
|
||||||
|
|
||||||
|
<div class="grid">
|
||||||
|
<div class="column">
|
||||||
|
<h2>Inactive</h2>
|
||||||
<ion-item>
|
<ion-item>
|
||||||
<ion-label position="floating">Floating: input</ion-label>
|
<ion-label position="floating">Label</ion-label>
|
||||||
<ion-input></ion-input>
|
<ion-input placeholder="Placeholder Text"></ion-input>
|
||||||
</ion-item>
|
</ion-item>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="column">
|
||||||
|
<h2>Focused</h2>
|
||||||
<ion-item class="item-has-focus">
|
<ion-item class="item-has-focus">
|
||||||
<ion-label position="floating">Floating: input focused value</ion-label>
|
<ion-label position="floating">Label</ion-label>
|
||||||
<ion-input value="value"></ion-input>
|
<ion-input placeholder="Placeholder Text"></ion-input>
|
||||||
</ion-item>
|
</ion-item>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="column">
|
||||||
|
<h2>Activated</h2>
|
||||||
<ion-item>
|
<ion-item>
|
||||||
<ion-label position="stacked">Stacked: input</ion-label>
|
<ion-label position="floating">Label</ion-label>
|
||||||
|
<ion-input placeholder="Placeholder Text" value="Input Text"></ion-input>
|
||||||
|
</ion-item>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="column">
|
||||||
|
<h2>Hover</h2>
|
||||||
|
<ion-item class="item-hovered">
|
||||||
|
<ion-label position="floating">Label</ion-label>
|
||||||
<ion-input></ion-input>
|
<ion-input></ion-input>
|
||||||
</ion-item>
|
</ion-item>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="column">
|
||||||
|
<h2>Disabled</h2>
|
||||||
<ion-item>
|
<ion-item>
|
||||||
<ion-label position="stacked">Stacked: input value</ion-label>
|
<ion-label position="floating">Label</ion-label>
|
||||||
<ion-input value="value"></ion-input>
|
<ion-input disabled></ion-input>
|
||||||
</ion-item>
|
</ion-item>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="column">
|
||||||
|
<h2>Toggle Placeholder</h2>
|
||||||
<ion-item>
|
<ion-item>
|
||||||
<ion-label position="stacked">Stacked: div</ion-label>
|
<ion-label position="floating">Label</ion-label>
|
||||||
|
<ion-input id="floatingToggle" type="password"></ion-input>
|
||||||
|
<ion-button fill="clear" slot="end" onClick="togglePlaceholder('#floatingToggle')" class="ion-align-self-center">
|
||||||
|
Toggle
|
||||||
|
</ion-button>
|
||||||
|
</ion-item>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h1>Stacked Inputs</h1>
|
||||||
|
|
||||||
|
<div class="grid">
|
||||||
|
<div class="column">
|
||||||
|
<h2>Inactive</h2>
|
||||||
|
<ion-item>
|
||||||
|
<ion-label position="stacked">Label</ion-label>
|
||||||
|
<ion-input></ion-input>
|
||||||
|
</ion-item>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="column">
|
||||||
|
<h2>Focused</h2>
|
||||||
|
<ion-item class="item-has-focus">
|
||||||
|
<ion-label position="stacked">Label</ion-label>
|
||||||
|
<ion-input placeholder="Placeholder Text"></ion-input>
|
||||||
|
</ion-item>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="column">
|
||||||
|
<h2>Activated</h2>
|
||||||
|
<ion-item>
|
||||||
|
<ion-label position="stacked">Label</ion-label>
|
||||||
|
<ion-input placeholder="Placeholder Text" value="Input Text"></ion-input>
|
||||||
|
</ion-item>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="column">
|
||||||
|
<h2>Hover</h2>
|
||||||
|
<ion-item class="item-hovered">
|
||||||
|
<ion-label position="stacked">Label</ion-label>
|
||||||
|
<ion-input></ion-input>
|
||||||
|
</ion-item>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="column">
|
||||||
|
<h2>Disabled</h2>
|
||||||
|
<ion-item>
|
||||||
|
<ion-label position="stacked">Label</ion-label>
|
||||||
|
<ion-input disabled></ion-input>
|
||||||
|
</ion-item>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="column">
|
||||||
|
<h2>Toggle Placeholder</h2>
|
||||||
|
<ion-item>
|
||||||
|
<ion-label position="stacked">Label</ion-label>
|
||||||
|
<ion-input id="stackedToggle" type="password"></ion-input>
|
||||||
|
<ion-button fill="clear" slot="end" onClick="togglePlaceholder('#stackedToggle')" class="ion-align-self-center">
|
||||||
|
Toggle
|
||||||
|
</ion-button>
|
||||||
|
</ion-item>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
<h2>Stacked Div</h2>
|
||||||
|
<ion-item>
|
||||||
|
<ion-label position="stacked">Label</ion-label>
|
||||||
<div>A div</div>
|
<div>A div</div>
|
||||||
</ion-item>
|
</ion-item>
|
||||||
|
|
||||||
<ion-item class="ion-align-items-center">
|
<ion-item class="ion-align-items-center">
|
||||||
<ion-icon slot="start" name="planet"></ion-icon>
|
<ion-icon slot="start" name="planet"></ion-icon>
|
||||||
<ion-label position="stacked">Align items: center</ion-label>
|
<ion-label position="stacked">Align items: center</ion-label>
|
||||||
@ -68,8 +171,45 @@
|
|||||||
</ion-content>
|
</ion-content>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
h1 {
|
||||||
|
font-size: 14px;
|
||||||
|
color: #54575e;
|
||||||
|
|
||||||
|
margin: 25px 0 5px 25px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: normal;
|
||||||
|
|
||||||
|
color: #a1a7b0;
|
||||||
|
|
||||||
|
margin-top: 10px;
|
||||||
|
margin-left: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
hr {
|
||||||
|
background: #eff1f3;
|
||||||
|
|
||||||
|
margin-top: 18px;
|
||||||
|
margin-bottom: 25px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(2, 1fr);
|
||||||
|
row-gap: 20px;
|
||||||
|
column-gap: 20px;
|
||||||
|
padding: 0 20px 20px;
|
||||||
|
}
|
||||||
|
|
||||||
ion-item {
|
ion-item {
|
||||||
--background: #f5f5f5;
|
--background: #e0e0e0;
|
||||||
|
--background-hover: #d3d3d3;
|
||||||
}
|
}
|
||||||
|
|
||||||
.custom {
|
.custom {
|
||||||
@ -84,6 +224,13 @@
|
|||||||
color: purple !important;
|
color: purple !important;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function togglePlaceholder(id) {
|
||||||
|
const input = document.querySelector(id);
|
||||||
|
input.placeholder = input.placeholder ? undefined : 'Placeholder Text';
|
||||||
|
}
|
||||||
|
</script>
|
||||||
</ion-app>
|
</ion-app>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
@ -35,12 +35,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
:host-context(.item-has-focus).label-floating,
|
:host-context(.item-has-focus).label-floating,
|
||||||
:host-context(.item-has-placeholder).label-floating,
|
|
||||||
:host-context(.item-has-value).label-floating {
|
:host-context(.item-has-value).label-floating {
|
||||||
@include transform(translate3d(0, 0, 0), scale(.82));
|
@include transform(translate3d(0, 0, 0), scale(.82));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// iOS Typography
|
// iOS Typography
|
||||||
// --------------------------------------------------
|
// --------------------------------------------------
|
||||||
|
|
||||||
|
@ -39,7 +39,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
:host-context(.item-has-focus).label-floating,
|
:host-context(.item-has-focus).label-floating,
|
||||||
:host-context(.item-has-placeholder).label-floating,
|
|
||||||
:host-context(.item-has-value).label-floating {
|
:host-context(.item-has-value).label-floating {
|
||||||
@include transform(translateY(50%), scale(.75));
|
@include transform(translateY(50%), scale(.75));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user