feat(turbo): add enable and disable mutations
This commit is contained in:
parent
cfb83bbdda
commit
1500a1cf28
2 changed files with 19 additions and 1 deletions
|
@ -31,5 +31,13 @@ module TurboStreamHelper
|
||||||
def focus_all(targets)
|
def focus_all(targets)
|
||||||
dispatch('dom:mutation', { action: :focus, targets: targets })
|
dispatch('dom:mutation', { action: :focus, targets: targets })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def disable(target)
|
||||||
|
dispatch('dom:mutation', { action: :disable, target: target })
|
||||||
|
end
|
||||||
|
|
||||||
|
def enable(target)
|
||||||
|
dispatch('dom:mutation', { action: :enable, target: target })
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,7 +18,7 @@ export class TurboEventController extends ApplicationController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const MutationAction = z.enum(['show', 'hide', 'focus']);
|
const MutationAction = z.enum(['show', 'hide', 'focus', 'enable', 'disable']);
|
||||||
type MutationAction = z.infer<typeof MutationAction>;
|
type MutationAction = z.infer<typeof MutationAction>;
|
||||||
const Mutation = z.union([
|
const Mutation = z.union([
|
||||||
z.object({
|
z.object({
|
||||||
|
@ -55,6 +55,16 @@ const Mutations: Record<MutationAction, (mutation: Mutation) => void> = {
|
||||||
for (const element of findElements(mutation)) {
|
for (const element of findElements(mutation)) {
|
||||||
element.focus();
|
element.focus();
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
disable: (mutation) => {
|
||||||
|
for (const element of findElements<HTMLInputElement>(mutation)) {
|
||||||
|
element.disabled = true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
enable: (mutation) => {
|
||||||
|
for (const element of findElements<HTMLInputElement>(mutation)) {
|
||||||
|
element.disabled = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue