Drive SearchField root attrs from Soma runtime

active-uix
dev 5 months ago
parent c6cf313734
commit 89243e2f52

@ -18,12 +18,12 @@ export const searchFieldMorfo = {
defaultElement: 'div', defaultElement: 'div',
optional: false, optional: false,
data: [ data: [
{ attr: 'data-disabled', severity: 'optional' }, { attr: 'data-disabled', value: v.propRef('disabled'), severity: 'optional' },
{ attr: 'data-readonly', severity: 'optional' }, { attr: 'data-readonly', value: v.propRef('readonly'), severity: 'optional' },
{ attr: 'data-invalid', severity: 'optional' }, { attr: 'data-invalid', value: v.propRef('invalid'), severity: 'optional' },
{ attr: 'data-required', severity: 'optional' }, { attr: 'data-required', value: v.propRef('required'), severity: 'optional' },
{ attr: 'data-focused', severity: 'optional' }, { attr: 'data-focused', value: v.propRef('focused'), severity: 'optional' },
{ attr: 'data-empty', severity: 'optional' } { attr: 'data-empty', value: v.propRef('empty'), severity: 'optional' }
], ],
aria: [] aria: []
}, },
@ -36,8 +36,8 @@ export const searchFieldMorfo = {
role: 'searchbox', role: 'searchbox',
optional: false, optional: false,
data: [ data: [
{ attr: 'data-disabled', severity: 'optional' }, { attr: 'data-disabled', value: v.propRef('disabled'), severity: 'optional' },
{ attr: 'data-readonly', severity: 'optional' } { attr: 'data-readonly', value: v.propRef('readonly'), severity: 'optional' }
], ],
aria: [ aria: [
{ attr: 'type', value: v.literal('search') }, { attr: 'type', value: v.literal('search') },
@ -70,7 +70,7 @@ export const searchFieldMorfo = {
defaultElement: 'button', defaultElement: 'button',
role: 'button', role: 'button',
optional: true, optional: true,
data: [{ attr: 'data-disabled', severity: 'optional' }], data: [{ attr: 'data-disabled', value: v.propRef('clearDisabled'), severity: 'optional' }],
aria: [ aria: [
{ attr: 'type', value: v.literal('button') }, { attr: 'type', value: v.literal('button') },
{ {

@ -68,12 +68,24 @@ export class SearchFieldProvider {
private constructor(opts: SearchFieldOpts) { private constructor(opts: SearchFieldOpts) {
this.opts = opts; this.opts = opts;
this.soma = Soma.require(); this.soma = Soma.require();
this.runtime = this.soma.runtime(searchFieldMorfo, {}); this.runtime = this.soma.runtime(searchFieldMorfo, {
props: {
disabled: () => this.isDisabled,
readonly: () => this.isReadonly,
invalid: () => this.isInvalid,
required: () => this.isRequired,
focused: () => this.focused,
empty: () => this.isEmpty,
clearDisabled: () => this.isDisabled || this.isReadonly || this.isEmpty,
clearOnEscape: () => this.opts.clearOnEscape.current
}
});
this.runtimePart = this.runtime.part('provider', { this.runtimePart = this.runtime.part('provider', {
id: opts.id, id: opts.id,
ref: opts.ref, ref: opts.ref,
owner: this, owner: this,
context: SearchFieldProvider.ctx context: SearchFieldProvider.ctx,
syncAttrs: true
}); });
// Register the Input's id with the parent Field so `Field.Label`'s // Register the Input's id with the parent Field so `Field.Label`'s
// `for` attribute lands on the interactive element. Direct assign — // `for` attribute lands on the interactive element. Direct assign —
@ -177,13 +189,7 @@ export class SearchFieldProvider {
readonly props = $derived.by(() => readonly props = $derived.by(() =>
this.runtimePart.assert({ this.runtimePart.assert({
...this.runtimePart.props, ...this.runtimePart.props
'data-disabled': boolToEmptyStrOrUndef(this.isDisabled),
'data-readonly': boolToEmptyStrOrUndef(this.isReadonly),
'data-invalid': boolToEmptyStrOrUndef(this.isInvalid),
'data-required': boolToEmptyStrOrUndef(this.isRequired),
'data-focused': boolToEmptyStrOrUndef(this.focused),
'data-empty': boolToEmptyStrOrUndef(this.isEmpty)
} as const) } as const)
); );
} }

Loading…
Cancel
Save

Powered by TurnKey Linux.