@tooark/web-components 1.5.0 → 1.6.1
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/README.md +4 -4
- package/README.pt-BR.md +4 -4
- package/dist/index.cjs +72 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +72 -7
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.d.cts
CHANGED
|
@@ -104,7 +104,8 @@ declare class ArkBadge extends HTMLElementBase {
|
|
|
104
104
|
*
|
|
105
105
|
* O PRÓPRIO host é o controle: recebe as classes, `role="button"`, foco,
|
|
106
106
|
* teclado (Enter/Espaço) e participa de formulários via ElementInternals
|
|
107
|
-
* (`type="submit"`/`"reset"
|
|
107
|
+
* (`type="submit"`/`"reset"`; o primeiro de submit é o botão padrão do Enter
|
|
108
|
+
* nos campos do formulário). Nenhum filho do usuário é movido ou envolvido,
|
|
108
109
|
* então frameworks que gerenciam os filhos (React, Vue, Angular) continuam
|
|
109
110
|
* donos deles. Com `href`, um `<a>` "esticado" cobre o host, recebe o foco e
|
|
110
111
|
* é nomeado pelo conteúdo do host (`aria-labelledby`).
|
|
@@ -120,6 +121,8 @@ declare class ArkButton extends HTMLElementBase {
|
|
|
120
121
|
private ownClasses;
|
|
121
122
|
private syncingClass;
|
|
122
123
|
private formDisabled;
|
|
124
|
+
/** Listener único de Enter no documento, instalado pelo primeiro botão conectado. */
|
|
125
|
+
private static implicitSubmitInstalled;
|
|
123
126
|
/**
|
|
124
127
|
* Atributos observados pelo componente, a que ele reage em attributeChangedCallback.
|
|
125
128
|
* @returns Array de nomes de atributos observados.
|
|
@@ -182,6 +185,11 @@ declare class ArkButton extends HTMLElementBase {
|
|
|
182
185
|
* @param event Evento de clique.
|
|
183
186
|
*/
|
|
184
187
|
private readonly handleClick;
|
|
188
|
+
private static installImplicitSubmit;
|
|
189
|
+
/** Enter num campo de texto do formulário clica o primeiro `ark-button` de submit, como o botão padrão nativo. */
|
|
190
|
+
private static readonly handleImplicitSubmit;
|
|
191
|
+
/** Primeiro `ark-button` de submit do formulário, ou nenhum quando há um submit nativo (o navegador já o clica). */
|
|
192
|
+
private static defaultButton;
|
|
185
193
|
/**
|
|
186
194
|
* Manipula o pressionamento de tecla no botão, tratando Enter e Espaço.
|
|
187
195
|
* @param event Evento de teclado.
|
|
@@ -726,6 +734,7 @@ declare class ArkDatepicker extends HTMLElementBase {
|
|
|
726
734
|
private emitChange;
|
|
727
735
|
private readonly handleCalendarChange;
|
|
728
736
|
private readonly handleClockChange;
|
|
737
|
+
/** Aplica o texto digitado no campo; `false` quando ele era inválido e o campo voltou ao último valor válido. */
|
|
729
738
|
private commitTyped;
|
|
730
739
|
private focusPanel;
|
|
731
740
|
private openPopup;
|
package/dist/index.d.ts
CHANGED
|
@@ -104,7 +104,8 @@ declare class ArkBadge extends HTMLElementBase {
|
|
|
104
104
|
*
|
|
105
105
|
* O PRÓPRIO host é o controle: recebe as classes, `role="button"`, foco,
|
|
106
106
|
* teclado (Enter/Espaço) e participa de formulários via ElementInternals
|
|
107
|
-
* (`type="submit"`/`"reset"
|
|
107
|
+
* (`type="submit"`/`"reset"`; o primeiro de submit é o botão padrão do Enter
|
|
108
|
+
* nos campos do formulário). Nenhum filho do usuário é movido ou envolvido,
|
|
108
109
|
* então frameworks que gerenciam os filhos (React, Vue, Angular) continuam
|
|
109
110
|
* donos deles. Com `href`, um `<a>` "esticado" cobre o host, recebe o foco e
|
|
110
111
|
* é nomeado pelo conteúdo do host (`aria-labelledby`).
|
|
@@ -120,6 +121,8 @@ declare class ArkButton extends HTMLElementBase {
|
|
|
120
121
|
private ownClasses;
|
|
121
122
|
private syncingClass;
|
|
122
123
|
private formDisabled;
|
|
124
|
+
/** Listener único de Enter no documento, instalado pelo primeiro botão conectado. */
|
|
125
|
+
private static implicitSubmitInstalled;
|
|
123
126
|
/**
|
|
124
127
|
* Atributos observados pelo componente, a que ele reage em attributeChangedCallback.
|
|
125
128
|
* @returns Array de nomes de atributos observados.
|
|
@@ -182,6 +185,11 @@ declare class ArkButton extends HTMLElementBase {
|
|
|
182
185
|
* @param event Evento de clique.
|
|
183
186
|
*/
|
|
184
187
|
private readonly handleClick;
|
|
188
|
+
private static installImplicitSubmit;
|
|
189
|
+
/** Enter num campo de texto do formulário clica o primeiro `ark-button` de submit, como o botão padrão nativo. */
|
|
190
|
+
private static readonly handleImplicitSubmit;
|
|
191
|
+
/** Primeiro `ark-button` de submit do formulário, ou nenhum quando há um submit nativo (o navegador já o clica). */
|
|
192
|
+
private static defaultButton;
|
|
185
193
|
/**
|
|
186
194
|
* Manipula o pressionamento de tecla no botão, tratando Enter e Espaço.
|
|
187
195
|
* @param event Evento de teclado.
|
|
@@ -726,6 +734,7 @@ declare class ArkDatepicker extends HTMLElementBase {
|
|
|
726
734
|
private emitChange;
|
|
727
735
|
private readonly handleCalendarChange;
|
|
728
736
|
private readonly handleClockChange;
|
|
737
|
+
/** Aplica o texto digitado no campo; `false` quando ele era inválido e o campo voltou ao último valor válido. */
|
|
729
738
|
private commitTyped;
|
|
730
739
|
private focusPanel;
|
|
731
740
|
private openPopup;
|
package/dist/index.js
CHANGED
|
@@ -681,12 +681,28 @@ const STATUS_SVG = {
|
|
|
681
681
|
</svg>`
|
|
682
682
|
};
|
|
683
683
|
let arkButtonIdCounter = 0;
|
|
684
|
+
/** Tipos de `<input>` em que o Enter submete o formulário (os campos que bloqueiam a submissão implícita no HTML). */
|
|
685
|
+
const IMPLICIT_SUBMIT_TYPES = new Set([
|
|
686
|
+
"text",
|
|
687
|
+
"search",
|
|
688
|
+
"email",
|
|
689
|
+
"url",
|
|
690
|
+
"tel",
|
|
691
|
+
"password",
|
|
692
|
+
"number",
|
|
693
|
+
"date",
|
|
694
|
+
"month",
|
|
695
|
+
"week",
|
|
696
|
+
"time",
|
|
697
|
+
"datetime-local"
|
|
698
|
+
]);
|
|
684
699
|
/**
|
|
685
700
|
* Botão da família Ark.
|
|
686
701
|
*
|
|
687
702
|
* O PRÓPRIO host é o controle: recebe as classes, `role="button"`, foco,
|
|
688
703
|
* teclado (Enter/Espaço) e participa de formulários via ElementInternals
|
|
689
|
-
* (`type="submit"`/`"reset"
|
|
704
|
+
* (`type="submit"`/`"reset"`; o primeiro de submit é o botão padrão do Enter
|
|
705
|
+
* nos campos do formulário). Nenhum filho do usuário é movido ou envolvido,
|
|
690
706
|
* então frameworks que gerenciam os filhos (React, Vue, Angular) continuam
|
|
691
707
|
* donos deles. Com `href`, um `<a>` "esticado" cobre o host, recebe o foco e
|
|
692
708
|
* é nomeado pelo conteúdo do host (`aria-labelledby`).
|
|
@@ -815,6 +831,7 @@ class ArkButton extends HTMLElementBase {
|
|
|
815
831
|
*/
|
|
816
832
|
connectedCallback() {
|
|
817
833
|
upgradeProperties(this);
|
|
834
|
+
ArkButton.installImplicitSubmit();
|
|
818
835
|
this.updateAppearance();
|
|
819
836
|
}
|
|
820
837
|
/**
|
|
@@ -930,6 +947,30 @@ class ArkButton extends HTMLElementBase {
|
|
|
930
947
|
get form() {
|
|
931
948
|
return this.internals?.form ?? this.closest("form");
|
|
932
949
|
}
|
|
950
|
+
// O navegador só reconhece como botão padrão do formulário um botão de submit nativo; um elemento form-associated
|
|
951
|
+
// nunca entra na submissão implícita, e um formulário com dois campos (login) não enviava no Enter. Fase de bolha:
|
|
952
|
+
// o Enter que um componente ou o app já cancelou fica com eles.
|
|
953
|
+
static installImplicitSubmit() {
|
|
954
|
+
if (ArkButton.implicitSubmitInstalled)
|
|
955
|
+
return;
|
|
956
|
+
ArkButton.implicitSubmitInstalled = true;
|
|
957
|
+
document.addEventListener("keydown", ArkButton.handleImplicitSubmit);
|
|
958
|
+
}
|
|
959
|
+
/** Primeiro `ark-button` de submit do formulário, ou nenhum quando há um submit nativo (o navegador já o clica). */
|
|
960
|
+
static defaultButton(form) {
|
|
961
|
+
const elements = Array.from(form.elements);
|
|
962
|
+
// `form.elements` não lista o <input type="image">, que também é botão padrão.
|
|
963
|
+
const hasNativeSubmit = form.querySelector('input[type="image" i]') !== null ||
|
|
964
|
+
elements.some((el) => (el instanceof HTMLButtonElement && el.type === "submit") ||
|
|
965
|
+
(el instanceof HTMLInputElement && (el.type === "submit" || el.type === "image")));
|
|
966
|
+
if (hasNativeSubmit)
|
|
967
|
+
return null;
|
|
968
|
+
for (const el of elements) {
|
|
969
|
+
if (el instanceof ArkButton && el.type === "submit" && !el.hasAttribute("href"))
|
|
970
|
+
return el;
|
|
971
|
+
}
|
|
972
|
+
return null;
|
|
973
|
+
}
|
|
933
974
|
// --- Estilo ---
|
|
934
975
|
/**
|
|
935
976
|
* Normaliza o valor do intent, caindo em "primary" quando não é um dos valores válidos.
|
|
@@ -1259,6 +1300,26 @@ class ArkButton extends HTMLElementBase {
|
|
|
1259
1300
|
// `string`, e não o literal, para subclasses (ark-copy-button) redeclararem o próprio tag.
|
|
1260
1301
|
ArkButton.tagName = "ark-button";
|
|
1261
1302
|
ArkButton.formAssociated = true;
|
|
1303
|
+
/** Listener único de Enter no documento, instalado pelo primeiro botão conectado. */
|
|
1304
|
+
ArkButton.implicitSubmitInstalled = false;
|
|
1305
|
+
/** Enter num campo de texto do formulário clica o primeiro `ark-button` de submit, como o botão padrão nativo. */
|
|
1306
|
+
ArkButton.handleImplicitSubmit = (event) => {
|
|
1307
|
+
if (event.key !== "Enter" || event.defaultPrevented || event.isComposing)
|
|
1308
|
+
return;
|
|
1309
|
+
if (event.ctrlKey || event.metaKey || event.altKey)
|
|
1310
|
+
return;
|
|
1311
|
+
const field = event.composedPath()[0];
|
|
1312
|
+
if (!(field instanceof HTMLInputElement) || !IMPLICIT_SUBMIT_TYPES.has(field.type) || !field.form)
|
|
1313
|
+
return;
|
|
1314
|
+
const button = ArkButton.defaultButton(field.form);
|
|
1315
|
+
if (!button)
|
|
1316
|
+
return;
|
|
1317
|
+
// Sem o preventDefault, um formulário de campo único ainda seria submetido pelo navegador: dois envios.
|
|
1318
|
+
event.preventDefault();
|
|
1319
|
+
// Botão padrão desabilitado (ou carregando) bloqueia a submissão implícita, como no nativo.
|
|
1320
|
+
if (!button.isDisabled())
|
|
1321
|
+
button.click();
|
|
1322
|
+
};
|
|
1262
1323
|
|
|
1263
1324
|
/**
|
|
1264
1325
|
* Grid de mês inline para seleção de data — equivalente ao DateCalendar do MUI.
|
|
@@ -4623,8 +4684,10 @@ class ArkDatepicker extends HTMLElementBase {
|
|
|
4623
4684
|
if (event.target?.tagName !== "INPUT")
|
|
4624
4685
|
return;
|
|
4625
4686
|
if (event.key === "Enter") {
|
|
4626
|
-
|
|
4627
|
-
|
|
4687
|
+
// Enter confirma o texto digitado. Com o popup fechado e o texto aceito, segue para o formulário (submissão
|
|
4688
|
+
// implícita), como num <input type="date">; texto inválido volta ao último valor e não submete.
|
|
4689
|
+
if (!this.commitTyped() || this.popupOpen)
|
|
4690
|
+
event.preventDefault();
|
|
4628
4691
|
}
|
|
4629
4692
|
else if (event.key === "ArrowDown") {
|
|
4630
4693
|
event.preventDefault();
|
|
@@ -4762,10 +4825,11 @@ class ArkDatepicker extends HTMLElementBase {
|
|
|
4762
4825
|
composed: true
|
|
4763
4826
|
}));
|
|
4764
4827
|
}
|
|
4828
|
+
/** Aplica o texto digitado no campo; `false` quando ele era inválido e o campo voltou ao último valor válido. */
|
|
4765
4829
|
commitTyped() {
|
|
4766
4830
|
const input = this.inputComp?.inputElement;
|
|
4767
4831
|
if (!input)
|
|
4768
|
-
return;
|
|
4832
|
+
return true;
|
|
4769
4833
|
const text = input.value.trim();
|
|
4770
4834
|
const currentValue = this.getAttribute("value") || "";
|
|
4771
4835
|
if (!text) {
|
|
@@ -4775,22 +4839,23 @@ class ArkDatepicker extends HTMLElementBase {
|
|
|
4775
4839
|
this.pushValueToChildren();
|
|
4776
4840
|
this.emitChange();
|
|
4777
4841
|
}
|
|
4778
|
-
return;
|
|
4842
|
+
return true;
|
|
4779
4843
|
}
|
|
4780
4844
|
const parsed = this.parseDisplay(text);
|
|
4781
4845
|
if (!parsed) {
|
|
4782
4846
|
// Entrada inválida: reverte para o último valor válido.
|
|
4783
4847
|
this.updateInputDisplay();
|
|
4784
|
-
return;
|
|
4848
|
+
return false;
|
|
4785
4849
|
}
|
|
4786
4850
|
this.dateISO = parsed.dateISO ?? this.dateISO;
|
|
4787
4851
|
this.timeISO = parsed.timeISO ?? this.timeISO;
|
|
4788
4852
|
if (this.composeValue() === currentValue) {
|
|
4789
4853
|
this.updateInputDisplay();
|
|
4790
|
-
return;
|
|
4854
|
+
return true;
|
|
4791
4855
|
}
|
|
4792
4856
|
this.pushValueToChildren();
|
|
4793
4857
|
this.emitChange();
|
|
4858
|
+
return true;
|
|
4794
4859
|
}
|
|
4795
4860
|
// --- Popup ---
|
|
4796
4861
|
focusPanel() {
|