Skip to content

Commit

Permalink
fix text color in native select
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoskolodny committed Jun 5, 2024
1 parent 328e013 commit bab1eac
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 1 deletion.
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions src/__screenshot_tests__/form-select-screenshot-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,21 @@ test('Select - display all options', async () => {
expect(image).toMatchImageSnapshot();
});

test('Select - display all options in dark mode', async () => {
const page = await openStoryPage({
id: 'components-select--controlled',
isDarkMode: true,
device: 'DESKTOP',
});

const field = await screen.findByRole('button', {name: 'Select a fruit'});
await field.click();

const image = await page.screenshot();

expect(image).toMatchImageSnapshot();
});

test('Select - display all options over inverse', async () => {
const page = await openStoryPage({
id: 'components-select--controlled',
Expand Down Expand Up @@ -181,6 +196,22 @@ test('Select - display all options with native select', async () => {
expect(image).toMatchImageSnapshot();
});

test('Select - display all options with native select in dark mode', async () => {
const page = await openStoryPage({
id: 'components-select--controlled',
device: 'DESKTOP',
isDarkMode: true,
args: {native: true},
});

const field = await screen.findByLabelText('Select a fruit');
await field.click();

const image = await page.screenshot();

expect(image).toMatchImageSnapshot();
});

test('Select - display all options with native select over inverse', async () => {
const page = await openStoryPage({
id: 'components-select--controlled',
Expand Down
4 changes: 3 additions & 1 deletion src/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,9 @@ const Select: React.FC<SelectProps> = ({
<option value="" style={{display: 'none'}} />
)}
{options.map(({value: val, text}) => (
<option key={val} value={val}>
// Set color: 'initial' to avoid wrong text color in some browsers when using dark mode.
// Similar issue in another lib: https://github.com/chakra-ui/chakra-ui/issues/417#issue-566611352
<option key={val} value={val} style={{color: 'initial'}}>
{text}
</option>
))}
Expand Down

0 comments on commit bab1eac

Please sign in to comment.