diff --git a/packages/slate-schema/src/checkers.ts b/packages/slate-schema/src/checkers.ts
index 31435b9bc..484ec8151 100644
--- a/packages/slate-schema/src/checkers.ts
+++ b/packages/slate-schema/src/checkers.ts
@@ -130,7 +130,6 @@ export const checkAncestor = (
let g = 0
while (true) {
- count++
const group = groups[g] as ChildValidation | undefined
const child = parent.children[index] as Descendant | undefined
const childPath = parentPath.concat(index)
@@ -172,6 +171,12 @@ export const checkAncestor = (
continue
}
+ if (
+ child &&
+ Editor.isMatch(editor, [child, childPath], group.match || {})
+ ) {
+ count++
+ }
// Since we want to report overflow on last matching child we don't
// immediately v for count > max, but instead do so once we find
// a child that doesn't match.
@@ -197,7 +202,7 @@ export const checkAncestor = (
// If there's no child, we're either done, we're in an optional group, or
// we're missing a child in a group with a mininmum set.
if (!child) {
- if (group.min != null && count <= group.min) {
+ if (group.min != null && count < group.min) {
return [
rule,
{
diff --git a/packages/slate-schema/test/validations/children/min/invalid-second-with-match.js b/packages/slate-schema/test/validations/children/min/invalid-second-with-match.js
new file mode 100644
index 000000000..13aea49ea
--- /dev/null
+++ b/packages/slate-schema/test/validations/children/min/invalid-second-with-match.js
@@ -0,0 +1,26 @@
+/** @jsx jsx */
+
+import { jsx } from 'slate-hyperscript'
+
+export const schema = [
+ {
+ for: 'node',
+ match: { a: true },
+ validate: {
+ children: [
+ { match: { b: true }, min: 1 },
+ { match: { c: true }, min: 0 },
+ ],
+ },
+ },
+]
+
+export const input = (
+
+
+ one
+
+
+)
+
+export const output =
diff --git a/site/examples/forced-layout.js b/site/examples/forced-layout.js
index 88f725f8f..4e61896fc 100644
--- a/site/examples/forced-layout.js
+++ b/site/examples/forced-layout.js
@@ -15,7 +15,8 @@ const schema = [
],
},
normalize: (editor, error) => {
- const { code, path, index } = error
+ const { code, path } = error
+ const [index] = path
const type = index === 0 ? 'title' : 'paragraph'
switch (code) {
@@ -25,11 +26,11 @@ const schema = [
}
case 'child_min_invalid': {
const block = { type, children: [{ text: '', marks: [] }] }
- Editor.insertNodes(editor, block, { at: path.concat(index) })
+ Editor.insertNodes(editor, block, { at: path })
break
}
case 'child_max_invalid': {
- Editor.setNodes(editor, { type }, { at: path.concat(index) })
+ Editor.setNodes(editor, { type }, { at: path })
break
}
}