db-ui / mono

DB UX Design System Monorepo - Provides Design Tokens and components for Web UIs
https://db-ui.github.io/mono/review/main/
Apache License 2.0
27 stars 5 forks source link

Form Components: Accessibility Tree not updating when id changes #2588

Open nmerget opened 3 weeks ago

nmerget commented 3 weeks ago

Currently, we add a default id to our form components like textarea,input, etc. OnMount we update the id and which is connected with the <label>.

The accessibility tree isn't updating when this id changes. Therefore the label gets duplicated for screen-reader users: image

A solution could be to move the form-component into the <label> or work with aria-hidden ?

mfranzke commented 2 weeks ago

I don't see a use case for an id that would change after initially mounted. Is this mainly meant for resilience ?

nmerget commented 2 weeks ago

Our implementation looks like this:

    onMount(() => {
        state._id = props.id || 'input-' + uuid();
        state._dataListId = props.dataListId || `datalist-${uuid()}`;
    });

    onUpdate(() => {
        if (state._id) {
            state._messageId = state._id + DEFAULT_MESSAGE_ID_SUFFIX;
            state._validMessageId = state._id + DEFAULT_VALID_MESSAGE_ID_SUFFIX;
            state._invalidMessageId =
                state._id + DEFAULT_INVALID_MESSAGE_ID_SUFFIX;
        }
    }, [state._id]);

We need to connect all messages for aria-describedby