Skip to content

Commit

Permalink
Fix ionic-team#28665: do not float label because of slotted items
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikOnBike committed Oct 18, 2024
1 parent be7561d commit 4c54cf7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
7 changes: 7 additions & 0 deletions core/src/components/input/input.scss
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,13 @@
max-width: calc(100% / #{$form-control-label-stacked-scale});
}

/**
* This removes the slotted items on floating label when empty and no focus.
*/
:host(.input-label-placement-floating:not(.has-focus):not(.has-value)) .native-wrapper > [slot] {
display: none;
}

// Start/End Slots
// ----------------------------------------------------------------

Expand Down
7 changes: 2 additions & 5 deletions core/src/components/input/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ export class Input implements ComponentInterface {
}

render() {
const { disabled, fill, readonly, shape, inputId, labelPlacement, el, hasFocus, clearInputIcon } = this;
const { disabled, fill, readonly, shape, inputId, labelPlacement, hasFocus, clearInputIcon } = this;
const mode = getIonMode(this);
const value = this.getValue();
const inItem = hostContext('ion-item', this.el);
Expand All @@ -698,7 +698,6 @@ export class Input implements ComponentInterface {
const clearIconData = clearInputIcon ?? defaultClearIcon;

const hasValue = this.hasValue();
const hasStartEndSlots = el.querySelector('[slot="start"], [slot="end"]') !== null;

/**
* If the label is stacked, it should always sit above the input.
Expand All @@ -714,11 +713,9 @@ export class Input implements ComponentInterface {
* other when the label isn't floating above the input. This doesn't
* apply to the outline fill, but this was not accounted for to keep
* things consistent.
*
* TODO(FW-5592): Remove hasStartEndSlots condition
*/
const labelShouldFloat =
labelPlacement === 'stacked' || (labelPlacement === 'floating' && (hasValue || hasFocus || hasStartEndSlots));
labelPlacement === 'stacked' || (labelPlacement === 'floating' && (hasValue || hasFocus));

return (
<Host
Expand Down

0 comments on commit 4c54cf7

Please sign in to comment.