File tree 3 files changed +32
-4
lines changed
3 files changed +32
-4
lines changed Original file line number Diff line number Diff line change 39
39
40
40
<script >
41
41
import { MDCFloatingLabelFoundation } from ' @material/floating-label' ;
42
- import { ponyfill } from ' @material/dom' ;
43
42
import { onMount , getContext } from ' svelte' ;
44
43
import { get_current_component } from ' svelte/internal' ;
45
44
import {
48
47
useActions ,
49
48
dispatch ,
50
49
} from ' @smui/common/internal.js' ;
51
- const { estimateScrollWidth } = ponyfill;
52
50
53
51
const forwardEvents = forwardEventsBuilder (get_current_component ());
54
52
84
82
instance = new MDCFloatingLabelFoundation ({
85
83
addClass,
86
84
removeClass,
87
- getWidth : () => estimateScrollWidth (getElement ()),
85
+ getWidth : () => {
86
+ const el = getElement ();
87
+ const clone = el .cloneNode (true );
88
+ el .parentNode .appendChild (clone);
89
+ clone .classList .add (' smui-floating-label--remove-transition' );
90
+ clone .classList .add (' smui-floating-label--force-size' );
91
+ clone .classList .remove (' mdc-floating-label--float-above' );
92
+ const scrollWidth = clone .scrollWidth ;
93
+ el .parentNode .removeChild (clone);
94
+ return scrollWidth;
95
+ },
88
96
registerInteractionHandler : (evtType , handler ) =>
89
97
getElement ().addEventListener (evtType, handler),
90
98
deregisterInteractionHandler : (evtType , handler ) =>
Original file line number Diff line number Diff line change 1
1
@use ' @material/floating-label/mdc-floating-label' ;
2
+
3
+ .smui-floating-label--remove-transition {
4
+ transition : unset !important ;
5
+ }
6
+
7
+ .smui-floating-label--force-size {
8
+ position : absolute !important ;
9
+ transform : unset !important ;
10
+ }
Original file line number Diff line number Diff line change 22
22
' mdc-text-field--outlined' : variant === ' outlined' ,
23
23
' smui-text-field--standard' : variant === ' standard' && ! textarea ,
24
24
' mdc-text-field--no-label' : noLabel || (label == null && ! $$slots .label ),
25
- ' mdc-text-field--label-floating' : value != null && value !== ' ' ,
25
+ ' mdc-text-field--label-floating' :
26
+ focused || (value != null && value !== ' ' ),
26
27
' mdc-text-field--with-leading-icon' :
27
28
withLeadingIcon === uninitializedValue
28
29
? $$slots .leadingIcon
335
336
instance .setDisabled (disabled);
336
337
}
337
338
339
+ // React to changes of value from outside component.
340
+ let previousValue = value;
341
+ $: if (instance && valued && previousValue !== value) {
342
+ previousValue = value;
343
+ // Check the data is flowing down.
344
+ if (instance .getValue () !== value) {
345
+ instance .setValue (value);
346
+ }
347
+ }
348
+
338
349
if (addLayoutListener) {
339
350
removeLayoutListener = addLayoutListener (layout);
340
351
}
You can’t perform that action at this time.
0 commit comments