scb-wc-test 0.1.110 → 0.1.112
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/blazor/ScbBlazorInteropBase.cs +11 -0
- package/blazor/scb-blazor-bridge.js +293 -5
- package/mvc/components/scb-textfield/scb-textfield.js +76 -50
- package/mvc/scb-blazor-bridge.js +293 -5
- package/package.json +2 -2
- package/scb-textfield/scb-textfield.js +110 -75
- package/scb-wc-test.bundle.js +75 -49
|
@@ -1038,6 +1038,17 @@ namespace ScbBlazorDemo
|
|
|
1038
1038
|
return JS.InvokeVoidAsync("SCBBlazor.setVizSelectedChipById", id ?? string.Empty, selectedChip ?? string.Empty).AsTask();
|
|
1039
1039
|
}
|
|
1040
1040
|
|
|
1041
|
+
|
|
1042
|
+
protected Task SetVizViewAsync(int index, string view)
|
|
1043
|
+
{
|
|
1044
|
+
return JS.InvokeVoidAsync("SCBBlazor.setVizView", index, view ?? string.Empty).AsTask();
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
protected Task SetVizViewByIdAsync(string id, string view)
|
|
1048
|
+
{
|
|
1049
|
+
return JS.InvokeVoidAsync("SCBBlazor.setVizViewById", id ?? string.Empty, view ?? string.Empty).AsTask();
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1041
1052
|
// Nedan följer alla state-klasser som används i Razor views
|
|
1042
1053
|
|
|
1043
1054
|
protected sealed class HeaderState
|
|
@@ -58,6 +58,18 @@
|
|
|
58
58
|
function mirrorHeaderDrawer(el, isOpen) {
|
|
59
59
|
if (isOpen) el.setAttribute('drawer-open', '');
|
|
60
60
|
else el.removeAttribute('drawer-open');
|
|
61
|
+
|
|
62
|
+
// Spegla aria-expanded på menyknappen i headerns shadow DOM så att läget blir rätt även vid overlay-stängning
|
|
63
|
+
try {
|
|
64
|
+
const sr = el.shadowRoot;
|
|
65
|
+
if (sr) {
|
|
66
|
+
const btn =
|
|
67
|
+
sr.querySelector('.menu-trigger') ||
|
|
68
|
+
sr.querySelector('[data-drawer-toggle]') ||
|
|
69
|
+
sr.querySelector('[aria-controls]');
|
|
70
|
+
if (btn) btn.setAttribute('aria-expanded', String(!!isOpen));
|
|
71
|
+
}
|
|
72
|
+
} catch (_) {}
|
|
61
73
|
}
|
|
62
74
|
|
|
63
75
|
function mirrorHeaderSearch(el, ev) {
|
|
@@ -91,6 +103,19 @@
|
|
|
91
103
|
to: 'draweropen',
|
|
92
104
|
mirror: (el) => mirrorHeaderDrawer(el, false),
|
|
93
105
|
},
|
|
106
|
+
// Speglar headerns drawer-state även när drawern stängs/öppnas via overlay eller ESC
|
|
107
|
+
{
|
|
108
|
+
sel: 'scb-header',
|
|
109
|
+
from: 'scb-drawer-opened',
|
|
110
|
+
to: 'scb-drawer-opened',
|
|
111
|
+
mirror: (el) => mirrorHeaderDrawer(el, true),
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
sel: 'scb-header',
|
|
115
|
+
from: 'scb-drawer-closed',
|
|
116
|
+
to: 'scb-drawer-closed',
|
|
117
|
+
mirror: (el) => mirrorHeaderDrawer(el, false),
|
|
118
|
+
},
|
|
94
119
|
{ sel: 'scb-header', from: 'drawer-select', to: 'select' },
|
|
95
120
|
{ sel: 'scb-header', from: 'menu-click', to: 'menuclick' },
|
|
96
121
|
{
|
|
@@ -1968,6 +1993,46 @@ window.SCBBlazor.registerScbEventHandlers = function (dotNetRef) {
|
|
|
1968
1993
|
(function () {
|
|
1969
1994
|
'use strict';
|
|
1970
1995
|
|
|
1996
|
+
function buildAttrSelector(attr, value) {
|
|
1997
|
+
const v = String(value ?? '')
|
|
1998
|
+
.replace(/\\/g, '\\\\')
|
|
1999
|
+
.replace(/"/g, '\\"');
|
|
2000
|
+
return `[${attr}="${v}"]`;
|
|
2001
|
+
}
|
|
2002
|
+
|
|
2003
|
+
function getOpenState(el) {
|
|
2004
|
+
if (!el) return false;
|
|
2005
|
+
try {
|
|
2006
|
+
if (typeof el.open === 'boolean') return el.open;
|
|
2007
|
+
} catch (_) {}
|
|
2008
|
+
return el.hasAttribute && el.hasAttribute('open');
|
|
2009
|
+
}
|
|
2010
|
+
|
|
2011
|
+
function safeClick(el) {
|
|
2012
|
+
if (!el) return false;
|
|
2013
|
+
try {
|
|
2014
|
+
el.dispatchEvent(
|
|
2015
|
+
new MouseEvent('click', { bubbles: true, composed: true }),
|
|
2016
|
+
);
|
|
2017
|
+
return true;
|
|
2018
|
+
} catch (_) {}
|
|
2019
|
+
try {
|
|
2020
|
+
el.click();
|
|
2021
|
+
return true;
|
|
2022
|
+
} catch (_) {}
|
|
2023
|
+
return false;
|
|
2024
|
+
}
|
|
2025
|
+
|
|
2026
|
+
function findTrigger(kind, id, wantOpen) {
|
|
2027
|
+
if (!id) return null;
|
|
2028
|
+
const selectors = [];
|
|
2029
|
+
if (wantOpen) selectors.push(buildAttrSelector(`data-${kind}-open`, id));
|
|
2030
|
+
else selectors.push(buildAttrSelector(`data-${kind}-close`, id));
|
|
2031
|
+
selectors.push(buildAttrSelector(`data-${kind}-toggle`, id));
|
|
2032
|
+
selectors.push(buildAttrSelector('aria-controls', id));
|
|
2033
|
+
return document.querySelector(selectors.join(','));
|
|
2034
|
+
}
|
|
2035
|
+
|
|
1971
2036
|
function getByIndex(selector, index) {
|
|
1972
2037
|
const list = document.querySelectorAll(selector);
|
|
1973
2038
|
if (!list || list.length === 0) return null;
|
|
@@ -2018,8 +2083,50 @@ window.SCBBlazor.registerScbEventHandlers = function (dotNetRef) {
|
|
|
2018
2083
|
const header = document.querySelector('scb-header');
|
|
2019
2084
|
if (!header) return;
|
|
2020
2085
|
const isOpen = toBool(open);
|
|
2021
|
-
|
|
2022
|
-
|
|
2086
|
+
|
|
2087
|
+
// Markör på hosten används av getState för Header.DrawerOpen
|
|
2088
|
+
try {
|
|
2089
|
+
mirrorHeaderDrawer(header, isOpen);
|
|
2090
|
+
} catch (_) {
|
|
2091
|
+
if (isOpen) header.setAttribute('drawer-open', '');
|
|
2092
|
+
else header.removeAttribute('drawer-open');
|
|
2093
|
+
}
|
|
2094
|
+
|
|
2095
|
+
// Styr drawern som ligger inuti headerns shadow DOM (standard id: main-drawer)
|
|
2096
|
+
try {
|
|
2097
|
+
const sr = header.shadowRoot;
|
|
2098
|
+
if (sr) {
|
|
2099
|
+
const btn =
|
|
2100
|
+
sr.querySelector('.menu-trigger') ||
|
|
2101
|
+
sr.querySelector('[data-drawer-toggle]') ||
|
|
2102
|
+
sr.querySelector('[aria-controls]');
|
|
2103
|
+
|
|
2104
|
+
const drawerId =
|
|
2105
|
+
(btn &&
|
|
2106
|
+
(btn.getAttribute('aria-controls') ||
|
|
2107
|
+
btn.getAttribute('data-drawer-toggle'))) ||
|
|
2108
|
+
'main-drawer';
|
|
2109
|
+
|
|
2110
|
+
const safeId =
|
|
2111
|
+
window.CSS && typeof window.CSS.escape === 'function'
|
|
2112
|
+
? window.CSS.escape(String(drawerId))
|
|
2113
|
+
: String(drawerId);
|
|
2114
|
+
|
|
2115
|
+
const drawer =
|
|
2116
|
+
sr.querySelector(`#${safeId}`) ||
|
|
2117
|
+
sr.querySelector('scb-drawer');
|
|
2118
|
+
|
|
2119
|
+
if (drawer) {
|
|
2120
|
+
try {
|
|
2121
|
+
drawer.open = isOpen;
|
|
2122
|
+
} catch (_) {}
|
|
2123
|
+
if (isOpen) drawer.setAttribute('open', '');
|
|
2124
|
+
else drawer.removeAttribute('open');
|
|
2125
|
+
}
|
|
2126
|
+
}
|
|
2127
|
+
} catch (_) {}
|
|
2128
|
+
|
|
2129
|
+
// Trigga state-refresh i Blazor
|
|
2023
2130
|
dispatchChange(header, 'draweropen', { open: isOpen });
|
|
2024
2131
|
};
|
|
2025
2132
|
|
|
@@ -2037,16 +2144,28 @@ window.SCBBlazor.registerScbEventHandlers = function (dotNetRef) {
|
|
|
2037
2144
|
|
|
2038
2145
|
// Drawer och menu
|
|
2039
2146
|
|
|
2040
|
-
|
|
2147
|
+
api.setDrawerOpen = function (open) {
|
|
2041
2148
|
const drawer = document.querySelector('scb-drawer');
|
|
2042
2149
|
if (!drawer) return;
|
|
2150
|
+
|
|
2043
2151
|
const isOpen = toBool(open);
|
|
2152
|
+
const prev = getOpenState(drawer);
|
|
2153
|
+
if (prev === isOpen) return;
|
|
2154
|
+
|
|
2155
|
+
// Primärt: använd samma trigger-logik som i UI:t (aria-controls / data-drawer-*)
|
|
2156
|
+
const id = drawer.id;
|
|
2157
|
+
const trigger = findTrigger('drawer', id, isOpen);
|
|
2158
|
+
if (trigger) {
|
|
2159
|
+
safeClick(trigger);
|
|
2160
|
+
if (getOpenState(drawer) === isOpen) return;
|
|
2161
|
+
}
|
|
2162
|
+
|
|
2163
|
+
// Fallback: sätt open direkt
|
|
2044
2164
|
try {
|
|
2045
2165
|
drawer.open = isOpen;
|
|
2046
2166
|
} catch (_) {}
|
|
2047
2167
|
if (isOpen) drawer.setAttribute('open', '');
|
|
2048
2168
|
else drawer.removeAttribute('open');
|
|
2049
|
-
dispatchChange(drawer, 'openchange', { open: isOpen });
|
|
2050
2169
|
};
|
|
2051
2170
|
|
|
2052
2171
|
api.setDrawerText = function (label, subLabel) {
|
|
@@ -2273,15 +2392,40 @@ window.SCBBlazor.registerScbEventHandlers = function (dotNetRef) {
|
|
|
2273
2392
|
|
|
2274
2393
|
// Dialog, notification och snackbar
|
|
2275
2394
|
|
|
2276
|
-
|
|
2395
|
+
api.setDialogOpen = function (open) {
|
|
2277
2396
|
const dialog = document.querySelector('scb-dialog');
|
|
2278
2397
|
if (!dialog) return;
|
|
2398
|
+
|
|
2279
2399
|
const isOpen = toBool(open);
|
|
2400
|
+
const prev = getOpenState(dialog);
|
|
2401
|
+
if (prev === isOpen) return;
|
|
2402
|
+
|
|
2403
|
+
// Primärt: använd samma trigger-logik som i UI:t (aria-controls / data-dialog-*)
|
|
2404
|
+
const id = dialog.id;
|
|
2405
|
+
const trigger = findTrigger('dialog', id, isOpen);
|
|
2406
|
+
if (trigger) {
|
|
2407
|
+
safeClick(trigger);
|
|
2408
|
+
if (getOpenState(dialog) === isOpen) {
|
|
2409
|
+
// Dialogen behöver en normaliserad event-signal för att Blazor ska uppdatera state
|
|
2410
|
+
dispatchChange(dialog, 'openchange', { open: isOpen });
|
|
2411
|
+
return;
|
|
2412
|
+
}
|
|
2413
|
+
}
|
|
2414
|
+
|
|
2415
|
+
// Fallback: försök komponentens API om det finns
|
|
2416
|
+
try {
|
|
2417
|
+
if (isOpen && typeof dialog.showModal === 'function') dialog.showModal();
|
|
2418
|
+
else if (isOpen && typeof dialog.show === 'function') dialog.show();
|
|
2419
|
+
else if (!isOpen && typeof dialog.close === 'function') dialog.close();
|
|
2420
|
+
} catch (_) {}
|
|
2421
|
+
|
|
2422
|
+
// Sista fallback: sätt open direkt
|
|
2280
2423
|
try {
|
|
2281
2424
|
dialog.open = isOpen;
|
|
2282
2425
|
} catch (_) {}
|
|
2283
2426
|
if (isOpen) dialog.setAttribute('open', '');
|
|
2284
2427
|
else dialog.removeAttribute('open');
|
|
2428
|
+
|
|
2285
2429
|
dispatchChange(dialog, 'openchange', { open: isOpen });
|
|
2286
2430
|
};
|
|
2287
2431
|
|
|
@@ -2514,4 +2658,148 @@ window.SCBBlazor.registerScbEventHandlers = function (dotNetRef) {
|
|
|
2514
2658
|
} catch (_) {}
|
|
2515
2659
|
dispatchChange(viz, 'valuechange', { value });
|
|
2516
2660
|
};
|
|
2661
|
+
|
|
2662
|
+
api.setVizView = function (index, view) {
|
|
2663
|
+
const viz = getByIndex('scb-viz', index);
|
|
2664
|
+
if (!viz) return;
|
|
2665
|
+
setVizViewOnElement(viz, view);
|
|
2666
|
+
};
|
|
2667
|
+
|
|
2668
|
+
api.setVizViewById = function (id, view) {
|
|
2669
|
+
const viz = getById(id, 'scb-viz');
|
|
2670
|
+
if (!viz) return;
|
|
2671
|
+
setVizViewOnElement(viz, view);
|
|
2672
|
+
};
|
|
2673
|
+
|
|
2674
|
+
function setVizViewOnElement(viz, view) {
|
|
2675
|
+
const raw = view == null ? '' : String(view);
|
|
2676
|
+
const v = raw.trim().toLowerCase();
|
|
2677
|
+
const showTable = v === 'table' || v === 'tabell';
|
|
2678
|
+
|
|
2679
|
+
// Försöker först styra via viz egna UI (segmented) så att både vy och vald knapp hamnar i synk.
|
|
2680
|
+
try {
|
|
2681
|
+
const sr = viz.shadowRoot;
|
|
2682
|
+
if (sr) {
|
|
2683
|
+
const scbSegmented = sr.querySelector('scb-segmented-button');
|
|
2684
|
+
if (scbSegmented) {
|
|
2685
|
+
const targetLabel = showTable ? 'tabell' : 'diagram';
|
|
2686
|
+
const targetLabelAlt = showTable ? 'table' : 'chart';
|
|
2687
|
+
|
|
2688
|
+
const items = Array.from(
|
|
2689
|
+
scbSegmented.querySelectorAll('scb-segmented-item, button, [role="button"]'),
|
|
2690
|
+
);
|
|
2691
|
+
|
|
2692
|
+
const pickByLabel = (el) => {
|
|
2693
|
+
const label = (
|
|
2694
|
+
el.getAttribute('label') ||
|
|
2695
|
+
el.getAttribute('aria-label') ||
|
|
2696
|
+
(el.label ?? '')
|
|
2697
|
+
)
|
|
2698
|
+
.toString()
|
|
2699
|
+
.trim()
|
|
2700
|
+
.toLowerCase();
|
|
2701
|
+
const text = (el.textContent ?? '').toString().trim().toLowerCase();
|
|
2702
|
+
const s = `${label} ${text}`.trim();
|
|
2703
|
+
return s.includes(targetLabel) || s.includes(targetLabelAlt);
|
|
2704
|
+
};
|
|
2705
|
+
|
|
2706
|
+
let targetEl = items.find(pickByLabel);
|
|
2707
|
+
if (!targetEl && items.length >= 2) {
|
|
2708
|
+
targetEl = items[showTable ? 1 : 0];
|
|
2709
|
+
}
|
|
2710
|
+
|
|
2711
|
+
if (targetEl) {
|
|
2712
|
+
const itemValue = (
|
|
2713
|
+
targetEl.getAttribute('value') ||
|
|
2714
|
+
targetEl.getAttribute('data-value') ||
|
|
2715
|
+
(targetEl.value ?? '')
|
|
2716
|
+
)
|
|
2717
|
+
.toString()
|
|
2718
|
+
.trim();
|
|
2719
|
+
|
|
2720
|
+
if (itemValue) {
|
|
2721
|
+
try {
|
|
2722
|
+
scbSegmented.value = itemValue;
|
|
2723
|
+
} catch (_) {}
|
|
2724
|
+
}
|
|
2725
|
+
|
|
2726
|
+
if (typeof targetEl.click === 'function') {
|
|
2727
|
+
targetEl.click();
|
|
2728
|
+
}
|
|
2729
|
+
|
|
2730
|
+
return;
|
|
2731
|
+
}
|
|
2732
|
+
}
|
|
2733
|
+
|
|
2734
|
+
// Fallback för Material/Web eller annan intern implementation där knapparna ligger direkt i shadowRoot.
|
|
2735
|
+
const mdButtons = Array.from(sr.querySelectorAll('md-segmented-button'));
|
|
2736
|
+
const buttons = mdButtons.length
|
|
2737
|
+
? mdButtons
|
|
2738
|
+
: Array.from(sr.querySelectorAll('button, [role="button"]'));
|
|
2739
|
+
|
|
2740
|
+
if (buttons.length) {
|
|
2741
|
+
const targetLabel = showTable ? 'tabell' : 'diagram';
|
|
2742
|
+
const targetLabelAlt = showTable ? 'table' : 'chart';
|
|
2743
|
+
|
|
2744
|
+
const pickByLabel = (el) => {
|
|
2745
|
+
const label = (
|
|
2746
|
+
el.getAttribute('label') ||
|
|
2747
|
+
el.getAttribute('aria-label') ||
|
|
2748
|
+
(el.label ?? '')
|
|
2749
|
+
)
|
|
2750
|
+
.toString()
|
|
2751
|
+
.trim()
|
|
2752
|
+
.toLowerCase();
|
|
2753
|
+
const text = (el.textContent ?? '').toString().trim().toLowerCase();
|
|
2754
|
+
const s = `${label} ${text}`.trim();
|
|
2755
|
+
return s.includes(targetLabel) || s.includes(targetLabelAlt);
|
|
2756
|
+
};
|
|
2757
|
+
|
|
2758
|
+
let targetEl = buttons.find(pickByLabel);
|
|
2759
|
+
if (!targetEl && buttons.length >= 2) {
|
|
2760
|
+
targetEl = buttons[showTable ? 1 : 0];
|
|
2761
|
+
}
|
|
2762
|
+
|
|
2763
|
+
if (targetEl) {
|
|
2764
|
+
if (typeof targetEl.click === 'function') {
|
|
2765
|
+
targetEl.click();
|
|
2766
|
+
return;
|
|
2767
|
+
}
|
|
2768
|
+
|
|
2769
|
+
try {
|
|
2770
|
+
targetEl.dispatchEvent(
|
|
2771
|
+
new MouseEvent('click', { bubbles: true, composed: true }),
|
|
2772
|
+
);
|
|
2773
|
+
return;
|
|
2774
|
+
} catch (_) {}
|
|
2775
|
+
}
|
|
2776
|
+
}
|
|
2777
|
+
}
|
|
2778
|
+
} catch (_) {}
|
|
2779
|
+
|
|
2780
|
+
// Sista fallback: växlar synlighet på slottat innehåll.
|
|
2781
|
+
const diagramSlot = viz.querySelector('[slot="diagram"]');
|
|
2782
|
+
const tableSlot = viz.querySelector('[slot="table"]');
|
|
2783
|
+
|
|
2784
|
+
if (diagramSlot) {
|
|
2785
|
+
if (showTable) {
|
|
2786
|
+
diagramSlot.setAttribute('hidden', '');
|
|
2787
|
+
diagramSlot.style.setProperty('display', 'none', 'important');
|
|
2788
|
+
} else {
|
|
2789
|
+
diagramSlot.removeAttribute('hidden');
|
|
2790
|
+
diagramSlot.style.removeProperty('display');
|
|
2791
|
+
}
|
|
2792
|
+
}
|
|
2793
|
+
|
|
2794
|
+
if (tableSlot) {
|
|
2795
|
+
if (showTable) {
|
|
2796
|
+
tableSlot.removeAttribute('hidden');
|
|
2797
|
+
tableSlot.style.removeProperty('display');
|
|
2798
|
+
} else {
|
|
2799
|
+
tableSlot.setAttribute('hidden', '');
|
|
2800
|
+
tableSlot.style.setProperty('display', 'none', 'important');
|
|
2801
|
+
}
|
|
2802
|
+
}
|
|
2803
|
+
};
|
|
2804
|
+
|
|
2517
2805
|
})();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as v,n as a,
|
|
1
|
+
import{a as v,n as a,r as x,i as g,x as h,t as y}from"../../vendor/vendor.js";import"../../vendor/vendor-material.js";import"../scb-datepicker/scb-datepicker.js";import"../scb-icon-button/scb-icon-button.js";import"../scb-button/scb-button.js";import"../scb-divider/scb-divider.js";import"../../vendor/preload-helper.js";(function(){try{var t=typeof globalThis<"u"?globalThis:window;if(!t.__scb_ce_guard_installed__){t.__scb_ce_guard_installed__=!0;var e=customElements.define.bind(customElements);customElements.define=function(i,n,o){try{customElements.get(i)||e(i,n,o)}catch(p){var c=String(p||"");if(c.indexOf("already been used")===-1&&c.indexOf("NotSupportedError")===-1)throw p}}}}catch{}})();var _=Object.defineProperty,w=Object.getOwnPropertyDescriptor,m=t=>{throw TypeError(t)},r=(t,e,i,n)=>{for(var o=n>1?void 0:n?w(e,i):e,c=t.length-1,p;c>=0;c--)(p=t[c])&&(o=(n?p(e,i,o):p(o))||o);return n&&o&&_(e,i,o),o},k=(t,e,i)=>e.has(t)||m("Cannot "+i),$=(t,e,i)=>e.has(t)?m("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,i),d=(t,e,i)=>(k(t,e,"access private method"),i),l,f,b,u;let s=class extends g{constructor(){super(),$(this,l),this._internals=null,this._inputFocused=!1,this._kbShouldShowRing=!1,this._onGlobalKeydown=t=>{t.key==="Tab"&&(this._kbShouldShowRing=!0,this._inputFocused&&d(this,l,u).call(this))},this._onGlobalPointerDown=()=>{this._kbShouldShowRing=!1,this._inputFocused&&d(this,l,u).call(this)},this.type="text",this.label="",this.supportingText="",this.errorText="",this.leadingIcon="",this.name="",this.pattern="",this.value="",this.underLabel="",this.error=!1,this.disabled=!1,this.required=!1,this.spacing="",this.spacingTop="",this.spacingBottom="",this._form=null,this._formSubmitHandler=null,this._formResetHandler=null,this._initialValue="",this._inputId="",this._showDatepicker=!1,this._toggleDatepicker=()=>{this._showDatepicker=!this._showDatepicker},this._onDateSelected=t=>{if(this.value=t.detail.value,this._showDatepicker=!1,this._internals){const e=this.disabled?null:this.value;this._internals.setFormValue(e)}if(this.pattern){const e=new RegExp(this.pattern);this.error=!e.test(this.value)}this.dispatchEvent(new Event("input",{bubbles:!0,composed:!0})),this.dispatchEvent(new CustomEvent("onValueChanged",{detail:{value:this.value},bubbles:!0,composed:!0}))},"attachInternals"in this&&(this._internals=this.attachInternals())}render(){const t=this.leadingIcon?h`<md-icon class="scb-textfield-icon">${this.leadingIcon}</md-icon>`:null,e=this.error?h`<md-icon class="scb-textfield-error-icon" aria-hidden="true">error</md-icon>`:null;this.underLabel=this.error?this.errorText||"Ogiltig inmatning.":this.supportingText,this.value=this.value||"";const i=this.underLabel?`${this._inputId}-supporting-text`:void 0,n=this.type==="search"&&this.value?h`
|
|
2
2
|
<button
|
|
3
3
|
type="button"
|
|
4
4
|
class="scb-textfield-clear"
|
|
@@ -39,20 +39,22 @@ import{a as v,n as a,i as x,x as h,t as y}from"../../vendor/vendor.js";import"..
|
|
|
39
39
|
id="${this.underLabel?`${this._inputId}-supporting-text`:""}"
|
|
40
40
|
>${this.underLabel}</span
|
|
41
41
|
>
|
|
42
|
-
<div class="scb-textfield-wrapper
|
|
43
|
-
<
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
42
|
+
<div class="scb-textfield-wrapper">
|
|
43
|
+
<div class="ripple-wrapper">
|
|
44
|
+
<textarea
|
|
45
|
+
class="scb-textfield"
|
|
46
|
+
?disabled=${this.disabled}
|
|
47
|
+
name="${this.name}"
|
|
48
|
+
id="${this._inputId}"
|
|
49
|
+
?required=${this.required}
|
|
50
|
+
aria-invalid=${this.error?"true":"false"}
|
|
51
|
+
aria-describedby=${i}
|
|
52
|
+
>
|
|
52
53
|
${this.value}</textarea
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
>
|
|
55
|
+
<md-ripple></md-ripple>
|
|
56
|
+
<md-focus-ring class="input-ring"></md-focus-ring>
|
|
57
|
+
</div>
|
|
56
58
|
</div>
|
|
57
59
|
`:this.type==="date"?h`
|
|
58
60
|
<label class="scb-textfield-label" for="${this._inputId}">${this.label}</label>
|
|
@@ -61,28 +63,37 @@ ${this.value}</textarea
|
|
|
61
63
|
id="${this.underLabel?`${this._inputId}-supporting-text`:""}"
|
|
62
64
|
>${this.underLabel}</span
|
|
63
65
|
>
|
|
64
|
-
<div class="scb-textfield-wrapper"
|
|
66
|
+
<div class="scb-textfield-wrapper">
|
|
65
67
|
${t}
|
|
66
|
-
<
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
68
|
+
<div class="ripple-wrapper">
|
|
69
|
+
<input
|
|
70
|
+
class="scb-textfield${this.error?" has-error-icon":""}"
|
|
71
|
+
.value=${this.value}
|
|
72
|
+
type="text"
|
|
73
|
+
name="${this.name}"
|
|
74
|
+
id="${this._inputId}"
|
|
75
|
+
?disabled=${this.disabled}
|
|
76
|
+
?required=${this.required}
|
|
77
|
+
aria-invalid=${this.error?"true":"false"}
|
|
78
|
+
aria-describedby=${i}
|
|
79
|
+
readonly
|
|
80
|
+
/>
|
|
81
|
+
${e}
|
|
82
|
+
<md-ripple></md-ripple>
|
|
83
|
+
<md-focus-ring class="input-ring"></md-focus-ring>
|
|
84
|
+
</div>
|
|
85
|
+
<scb-icon-button
|
|
86
|
+
class="scb-textfield-datepicker-button"
|
|
87
|
+
icon="calendar_today"
|
|
88
|
+
@click=${this._toggleDatepicker}
|
|
89
|
+
aria-label="Välj datum"
|
|
90
|
+
></scb-icon-button>
|
|
79
91
|
<scb-datepicker
|
|
80
92
|
variant="popup"
|
|
81
93
|
.selectedValue=${this.value}
|
|
82
94
|
.open=${this._showDatepicker}
|
|
83
95
|
@date-selected=${this._onDateSelected}
|
|
84
96
|
></scb-datepicker>
|
|
85
|
-
${e}
|
|
86
97
|
</div>
|
|
87
98
|
`:h`
|
|
88
99
|
<label class="scb-textfield-label" for="${this._inputId}">${this.label}</label>
|
|
@@ -91,25 +102,27 @@ ${this.value}</textarea
|
|
|
91
102
|
id="${this.underLabel?`${this._inputId}-supporting-text`:""}"
|
|
92
103
|
>${this.underLabel}</span
|
|
93
104
|
>
|
|
94
|
-
<div class="scb-textfield-wrapper
|
|
105
|
+
<div class="scb-textfield-wrapper">
|
|
95
106
|
${t}
|
|
96
|
-
<
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
107
|
+
<div class="ripple-wrapper">
|
|
108
|
+
<input
|
|
109
|
+
class="scb-textfield${this.error?" has-error-icon":""}"
|
|
110
|
+
.value=${this.value}
|
|
111
|
+
type="${this.type}"
|
|
112
|
+
name="${this.name}"
|
|
113
|
+
id="${this._inputId}"
|
|
114
|
+
?disabled=${this.disabled}
|
|
115
|
+
?required=${this.required}
|
|
116
|
+
aria-invalid=${this.error?"true":"false"}
|
|
117
|
+
aria-describedby=${i}
|
|
118
|
+
/>
|
|
119
|
+
${n}
|
|
120
|
+
${e}
|
|
121
|
+
<md-ripple></md-ripple>
|
|
122
|
+
<md-focus-ring class="input-ring"></md-focus-ring>
|
|
123
|
+
</div>
|
|
111
124
|
</div>
|
|
112
|
-
`}firstUpdated(t){super.firstUpdated(t),this._initialValue=this.value;const e=this.shadowRoot?.querySelector(".scb-textfield");e&&(e.addEventListener("input",()=>{const i=e;if(this.value=i.value,this._internals){const
|
|
125
|
+
`}firstUpdated(t){super.firstUpdated(t),this._initialValue=this.value;const e=this.shadowRoot?.querySelector(".scb-textfield");e&&(e.addEventListener("input",()=>{const i=e;if(this.value=i.value,this._internals){const n=this.disabled?null:this.value;this._internals.setFormValue(n)}if(this.pattern){const n=new RegExp(this.pattern);this.error=!n.test(this.value)}this.dispatchEvent(new Event("input",{bubbles:!0,composed:!0})),this.dispatchEvent(new CustomEvent("onValueChanged",{detail:{value:this.value},bubbles:!0,composed:!0}))}),e.addEventListener("change",()=>{this.dispatchEvent(new Event("change",{bubbles:!0,composed:!0}))}),e.addEventListener("select",()=>{this.dispatchEvent(new Event("select",{bubbles:!0,composed:!0}))}),e.addEventListener("focus",()=>{this._inputFocused=!0,d(this,l,u).call(this)}),e.addEventListener("blur",()=>{this._inputFocused=!1,d(this,l,u).call(this)})),d(this,l,f).call(this)}updated(t){if(super.updated(t),this.toggleAttribute("aria-disabled",this.disabled),this._internals&&(t.has("value")||t.has("disabled"))){const e=this.disabled?null:this.value;this._internals.setFormValue(e)}(t.has("spacing")||t.has("spacingTop")||t.has("spacingBottom"))&&d(this,l,f).call(this)}formDisabledCallback(t){this.disabled=t}connectedCallback(){super.connectedCallback(),this._inputId=this.id||`scb-textfield-${Math.random().toString(36).substr(2,9)}`,this._formSubmitHandler=t=>{this.reportValidity()||(t.preventDefault(),t.stopPropagation())},this._form=this.closest("form"),this._form&&(this._form.addEventListener("submit",this._formSubmitHandler,!0),this._formResetHandler=()=>{this.value=this._initialValue;const t=this.shadowRoot?.querySelector(".scb-textfield");t&&(t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement)&&(t.value=this._initialValue),this.error=!1},this._form.addEventListener("reset",this._formResetHandler,!0)),window.addEventListener("keydown",this._onGlobalKeydown,!0),window.addEventListener("pointerdown",this._onGlobalPointerDown,!0)}disconnectedCallback(){super.disconnectedCallback(),this._form&&this._formSubmitHandler&&(this._form.removeEventListener("submit",this._formSubmitHandler,!0),this._formResetHandler&&this._form.removeEventListener("reset",this._formResetHandler,!0)),window.removeEventListener("keydown",this._onGlobalKeydown,!0),window.removeEventListener("pointerdown",this._onGlobalPointerDown,!0)}reportValidity(){const t=this.shadowRoot?.querySelector(".scb-textfield");if(t&&(t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement)){this.required&&!t.value?t.setCustomValidity(this.errorText||"Ogiltig inmatning."):t.setCustomValidity("");const e=t.reportValidity();this.error=!e;const i=e?"":this.errorText||t.validationMessage||"Ogiltig inmatning.";return e||(this.errorText=i),this._internals&&(e?this._internals.setValidity({}):this._internals.setValidity({customError:!0},i,t)),e}return!0}_onClearClick(){const t=this.shadowRoot?.querySelector(".scb-textfield");if(t&&(t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement)){if(t.value="",this.value="",this._internals){const e=this.disabled?null:this.value;this._internals.setFormValue(e),this._internals.setValidity({})}this.error=!1,t.setCustomValidity(""),this.dispatchEvent(new Event("input",{bubbles:!0,composed:!0})),this.dispatchEvent(new CustomEvent("onValueChanged",{detail:{value:this.value},bubbles:!0,composed:!0})),t.focus()}}};l=new WeakSet;f=function(){const t=d(this,l,b).call(this,this.spacing),e=d(this,l,b).call(this,this.spacingTop)??t,i=d(this,l,b).call(this,this.spacingBottom)??t;e?this.style.setProperty("--scb-textfield-spacing-block-start",e):this.style.removeProperty("--scb-textfield-spacing-block-start"),i?this.style.setProperty("--scb-textfield-spacing-block-end",i):this.style.removeProperty("--scb-textfield-spacing-block-end")};b=function(t){if(!t)return;const e=String(t).trim();if(e)return/^\d+$/.test(e)?`var(--spacing-${Math.max(0,Math.min(14,parseInt(e,10)))})`:e};u=function(){const t=this.renderRoot?.querySelector(".ripple-wrapper");t&&(this._inputFocused&&this._kbShouldShowRing?t.setAttribute("data-kb-focus","true"):t.removeAttribute("data-kb-focus"))};s.formAssociated=!0;s.styles=[v`
|
|
113
126
|
:host {
|
|
114
127
|
--scb-textfield-number-max-width: 280px;
|
|
115
128
|
--scb-textfield-text-max-width: 400px;
|
|
@@ -135,9 +148,6 @@ ${this.value}</textarea
|
|
|
135
148
|
:host([type='text']) {
|
|
136
149
|
--scb-textfield-max-width: var(--scb-textfield-text-max-width);
|
|
137
150
|
}
|
|
138
|
-
:host([type='date']) {
|
|
139
|
-
--scb-textfield-max-width: var(--scb-textfield-text-max-width);
|
|
140
|
-
}
|
|
141
151
|
:host([type='search']) {
|
|
142
152
|
--scb-textfield-max-width: var(--scb-textfield-search-max-width);
|
|
143
153
|
}
|
|
@@ -156,6 +166,9 @@ ${this.value}</textarea
|
|
|
156
166
|
:host([type='textarea']) {
|
|
157
167
|
--scb-textfield-max-width: var(--scb-textfield-textarea-max-width);
|
|
158
168
|
}
|
|
169
|
+
:host([type='date']) {
|
|
170
|
+
--scb-textfield-max-width: var(--scb-textfield-text-max-width);
|
|
171
|
+
}
|
|
159
172
|
|
|
160
173
|
:host {
|
|
161
174
|
display: flex;
|
|
@@ -214,6 +227,10 @@ ${this.value}</textarea
|
|
|
214
227
|
padding-right: var(--spacing-11);
|
|
215
228
|
}
|
|
216
229
|
|
|
230
|
+
:host([type='date']) .scb-textfield {
|
|
231
|
+
padding-right: var(--spacing-11);
|
|
232
|
+
}
|
|
233
|
+
|
|
217
234
|
md-icon + .scb-textfield {
|
|
218
235
|
padding-left: var(--spacing-10);
|
|
219
236
|
}
|
|
@@ -325,4 +342,13 @@ ${this.value}</textarea
|
|
|
325
342
|
height: 100%;
|
|
326
343
|
display: block;
|
|
327
344
|
}
|
|
328
|
-
|
|
345
|
+
|
|
346
|
+
/* Datumknappen ovanför input/ripple */
|
|
347
|
+
.scb-textfield-datepicker-button {
|
|
348
|
+
position: absolute;
|
|
349
|
+
right: var(--spacing-4);
|
|
350
|
+
top: 50%;
|
|
351
|
+
transform: translateY(-50%);
|
|
352
|
+
z-index: 4;
|
|
353
|
+
}
|
|
354
|
+
`];r([a({type:String,reflect:!0})],s.prototype,"type",2);r([a({type:String})],s.prototype,"label",2);r([a({type:String,attribute:"supporting-text"})],s.prototype,"supportingText",2);r([a({type:String,attribute:"error-text"})],s.prototype,"errorText",2);r([a({type:String,attribute:"leading-icon"})],s.prototype,"leadingIcon",2);r([a({type:String})],s.prototype,"name",2);r([a({type:String})],s.prototype,"pattern",2);r([a({type:String,attribute:"value"})],s.prototype,"value",2);r([a({type:String})],s.prototype,"underLabel",2);r([a({type:Boolean,reflect:!0})],s.prototype,"error",2);r([a({type:Boolean,reflect:!0})],s.prototype,"disabled",2);r([a({type:Boolean,reflect:!0})],s.prototype,"required",2);r([a({type:String,reflect:!0})],s.prototype,"spacing",2);r([a({type:String,attribute:"spacing-top",reflect:!0})],s.prototype,"spacingTop",2);r([a({type:String,attribute:"spacing-bottom",reflect:!0})],s.prototype,"spacingBottom",2);r([x()],s.prototype,"_showDatepicker",2);s=r([y("scb-textfield")],s);
|