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

fix(Select): long value overflow #827

Merged
merged 3 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 51 additions & 12 deletions src/__screenshot_tests__/form-select-screenshot-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,61 @@ test.each(devices)('Select elements on the initial state appear properly on %s',
expect(image).toMatchImageSnapshot();
});

test.each(devices)('Select elements on a selected state appear properly on %s', async (device) => {
test('Select elements on a selected state appear properly on DESKTOP', async () => {
const page = await openStoryPage({
id: 'components-select--default',
device,
device: 'DESKTOP',
});

const select = await screen.findByLabelText('Select a fruit (opcional)');
await select.click();
const selectOptions = await screen.findAllByRole('option', {name: 'Apple'});
// take the last one because the options are displayed in a portal, at the end of the body
await selectOptions?.at(-1)?.click();

const image = await page.screenshot({fullPage: true});
expect(image).toMatchImageSnapshot();
});

test('Select elements on a selected state appear properly on MOBILE_IOS', async () => {
const page = await openStoryPage({
id: 'components-select--default',
device: 'MOBILE_IOS',
});

const select = (await screen.findAllByRole('combobox'))[0];
await select.select('apple');

const image = await page.screenshot({fullPage: true});
expect(image).toMatchImageSnapshot();
});

test('Select elements on a selected state appear properly on DESKTOP with long texts', async () => {
const page = await openStoryPage({
id: 'components-select--default',
device: 'DESKTOP',
});

const select = await screen.findByLabelText('Select a fruit (opcional)');
await select.click();
const selectOptions = await screen.findAllByRole('option', {
name: 'A very very long text value for this option',
});
// take the last one because the options are displayed in a portal, at the end of the body
await selectOptions?.at(-1)?.click();

const image = await page.screenshot({fullPage: true});
expect(image).toMatchImageSnapshot();
});

test('Select elements on a selected state appear properly on MOBILE_IOS with long texts', async () => {
const page = await openStoryPage({
id: 'components-select--default',
device: 'MOBILE_IOS',
});

if (device === 'MOBILE_IOS') {
const select = (await screen.findAllByRole('combobox'))[0];
await select.select('apple');
} else {
const select = await screen.findByLabelText('Select a fruit (opcional)');
await select.click();
const selectOptions = await screen.findAllByRole('option', {name: 'Apple'});
// take the last one because the options are displayed in a portal, at the end of the body
await selectOptions?.at(-1)?.click();
}
const select = (await screen.findAllByRole('combobox'))[0];
await select.select('longValue');

const image = await page.screenshot({fullPage: true});
expect(image).toMatchImageSnapshot();
Expand Down
5 changes: 3 additions & 2 deletions src/__stories__/select-story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ export default {
component: Select,
};

const fruitOptions = fruitEntries.map(([text, value]) => ({text, value}));

export const Default: StoryComponent = () => {
const [value, setValue] = React.useState('');

const fruitOptions = fruitEntries.map(([text, value]) => ({text, value}));
fruitOptions.push({value: 'longValue', text: 'A very very long text value for this option'});

return (
<>
<Stack space={16} dataAttributes={{testid: 'select-story'}}>
Expand Down
2 changes: 2 additions & 0 deletions src/select.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export const selectContainerVariants = styleVariants({
const selectBase = style([
sprinkles({
border: 'none',
overflow: 'hidden',
color: skinVars.colors.textPrimary,
background: 'transparent', // FieldContainer gives the correct background color
width: '100%',
Expand Down Expand Up @@ -131,6 +132,7 @@ export const selectVariants = styleVariants({
const selectTextBase = style([
sprinkles({
position: 'absolute',
overflow: 'hidden',
maxWidth: '100%',
color: skinVars.colors.textPrimary,
}),
Expand Down
1 change: 1 addition & 0 deletions src/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ const Select: React.FC<SelectProps> = ({
style={{
paddingTop: label ? 24 : 16,
paddingBottom: label ? 8 : 16,
paddingRight: 48,
// Override default browser opacity when disabled. This opacity also affects the label.
// Without this fix, the label is invisible when disabled
opacity: 1,
Expand Down
Loading