@brightspace-ui/core 3.254.2 → 3.255.0
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.
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# FormElementContainerMixin
|
|
2
|
+
|
|
3
|
+
Extending `FormElementContainerMixin` will allow a custom element's children (native or [custom](./form-element-mixin.md)) to participate in the parent `<d2l-form>`.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
Simply extend the `FormElementContainerMixin`:
|
|
8
|
+
|
|
9
|
+
```javascript
|
|
10
|
+
import { FormElementContainerMixin } from '@brightspace-ui/core/form/form-element-container-mixin.js';
|
|
11
|
+
|
|
12
|
+
class MyCustomFormElementContainer extends FormElementContainerMixin(LitElement) {
|
|
13
|
+
render() {
|
|
14
|
+
html`
|
|
15
|
+
<d2l-input-text
|
|
16
|
+
label="First Name"
|
|
17
|
+
name="first-name"
|
|
18
|
+
required></d2l-input-text>
|
|
19
|
+
<d2l-input-text
|
|
20
|
+
label="Last Name"
|
|
21
|
+
name="last-name"
|
|
22
|
+
required></d2l-input-text>
|
|
23
|
+
`;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
customElements.define('my-custom-form-element-container', MyCustomFormElementContainer);
|
|
28
|
+
```
|
|
@@ -15,24 +15,34 @@ export const isElement = (node) => node && node.nodeType === Node.ELEMENT_NODE;
|
|
|
15
15
|
|
|
16
16
|
export const isCustomElement = (node) => isElement(node) && node.nodeName.indexOf('-') !== -1;
|
|
17
17
|
|
|
18
|
-
export const isCustomFormElement = (node) => isCustomElement(node) &&
|
|
18
|
+
export const isCustomFormElement = (node) => isCustomElement(node) && Boolean(node.formAssociated);
|
|
19
|
+
|
|
20
|
+
export const isCustomFormElementContainer = (node) => isCustomElement(node) && Boolean(node.isCustomFormElementContainer);
|
|
19
21
|
|
|
20
22
|
export const isNativeFormElement = (node) => {
|
|
21
23
|
if (!isElement(node)) {
|
|
22
24
|
return false;
|
|
23
25
|
}
|
|
24
26
|
const nodeName = node.nodeName.toLowerCase();
|
|
25
|
-
return
|
|
27
|
+
return Boolean(formElements[nodeName]);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const getElementChildren = (elem) => {
|
|
31
|
+
if (isCustomFormElementContainer(elem)) {
|
|
32
|
+
return elem.shadowRoot.children;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return elem.tagName === 'SLOT' && ['primary', 'secondary'].includes(elem.name) ? elem.assignedNodes() : elem.children;
|
|
26
36
|
};
|
|
27
37
|
|
|
28
|
-
const _findFormElementsHelper = (
|
|
29
|
-
if (isNativeFormElement(
|
|
30
|
-
|
|
38
|
+
const _findFormElementsHelper = (elem, elems, isFormElementPredicate, visitChildrenPredicate) => {
|
|
39
|
+
if (isNativeFormElement(elem) || isCustomFormElement(elem) || isFormElementPredicate(elem)) {
|
|
40
|
+
elems.push(elem);
|
|
31
41
|
}
|
|
32
|
-
if (visitChildrenPredicate(
|
|
33
|
-
const children =
|
|
42
|
+
if (visitChildrenPredicate(elem)) {
|
|
43
|
+
const children = getElementChildren(elem);
|
|
34
44
|
for (const child of children) {
|
|
35
|
-
_findFormElementsHelper(child,
|
|
45
|
+
_findFormElementsHelper(child, elems, isFormElementPredicate, visitChildrenPredicate);
|
|
36
46
|
}
|
|
37
47
|
}
|
|
38
48
|
};
|
package/custom-elements.json
CHANGED
|
@@ -4967,6 +4967,21 @@
|
|
|
4967
4967
|
}
|
|
4968
4968
|
]
|
|
4969
4969
|
},
|
|
4970
|
+
{
|
|
4971
|
+
"name": "d2l-custom-form-element-container",
|
|
4972
|
+
"path": "./components/form/demo/custom-form-element-container.js",
|
|
4973
|
+
"properties": [
|
|
4974
|
+
{
|
|
4975
|
+
"name": "styles",
|
|
4976
|
+
"type": "CSSResult[]",
|
|
4977
|
+
"default": "[\"inputStyles\",\"inputLabelStyles\"]"
|
|
4978
|
+
},
|
|
4979
|
+
{
|
|
4980
|
+
"name": "isCustomFormElementContainer",
|
|
4981
|
+
"type": "boolean"
|
|
4982
|
+
}
|
|
4983
|
+
]
|
|
4984
|
+
},
|
|
4970
4985
|
{
|
|
4971
4986
|
"name": "d2l-form-demo",
|
|
4972
4987
|
"path": "./components/form/demo/form-demo.js"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brightspace-ui/core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.255.0",
|
|
4
4
|
"description": "A collection of accessible, free, open-source web components for building Brightspace applications",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": "https://github.com/BrightspaceUI/core.git",
|