Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MultiSelect renders input value as a stringified array including the entire item objects, but it should display a readable value based on the selected option labels #7187

Closed
iamkyrylo opened this issue Sep 15, 2024 · 0 comments · Fixed by #7188 or #7216
Assignees
Labels
Component: Accessibility Issue or pull request is related to WCAG or ARIA
Milestone

Comments

@iamkyrylo
Copy link
Contributor

Describe the bug

There are two main issues with the current approach:

  • As a user with disabilities, I want to see the selected items in the combobox value, instead of a programmatic string.
  • As a developer, I want to test selected options in a normal way:
describe('MultiSelect', () => {
    it('should allow selecting multiple options', async () => {
        const user = userEvent();
        render(<MultiSelect aria-label="Countries" options={countries} optionLabel="name" />);

        await user.click(screen.getByRole('combobox', { name: 'Countries' }));
        await screen.findByRole('listbox', { name: 'Countries' });

        await user.click(screen.getByRole('option', { name: 'Rome' }));
        await user.click(screen.getByRole('option', { name: 'London' }));

        expect(screen.getByRole('combobox', { name: 'Countries' })).toHaveValue('Rome, London');
    });
});

In my view, the input value string should consist of the option labels - the values the user sees on the screen. The following logic should be enough to fix this issue:

const getInputValue = (value = []) => {
    if (props.optionLabel && Array.isArray(value)) {
        return value.map((val) => getLabelByValue(val)).join(', ');
    }

    return value;
};

const inputProps = mergeProps(
    {
        ...otherProps,
        value: getInputValue(props.value),
    },
    ptm('input')
);

Reproducer

No response

System Information

primereact: latest
react: 18.3.1

Steps to reproduce the behavior

  1. Open the basic example at PrimeReact MultiSelect Doc and choose a few options in the dropdown.
  2. Open the browser devtools and check the input value.

Screenshot example:

Screenshot 2024-09-15 at 13 07 16

Expected behavior

Screenshot 2024-09-15 at 13 13 52
@iamkyrylo iamkyrylo added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Sep 15, 2024
@melloware melloware added Component: Accessibility Issue or pull request is related to WCAG or ARIA and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Sep 15, 2024
@melloware melloware added this to the 10.8.3 milestone Sep 15, 2024
@melloware melloware removed this from the 10.8.3 milestone Sep 15, 2024
nitrogenous added a commit that referenced this issue Sep 16, 2024
Fix #7187: Provide readable input value based on selected option labels
@melloware melloware added this to the 10.8.4 milestone Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Accessibility Issue or pull request is related to WCAG or ARIA
Projects
None yet
2 participants