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

Select — Add theme.select.clear.container.hover #7397

Merged
merged 4 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 10 additions & 3 deletions src/js/components/Select/SelectContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,19 @@ const ClearButton = forwardRef(
ref={ref}
onClick={onClear}
focusIndicator={false}
plain
{...passThemeFlag}
{...rest}
>
<Box {...theme.select.clear.container} align={align}>
<Text {...theme.select.clear.text}>{buttonLabel}</Text>
</Box>
{({ hover }) => (
<Box
{...theme.select.clear.container}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this accidentally put a hover=[object, object] on the Box?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Collaborator Author

@taysea taysea Oct 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wasn't passing it to the DOM so originally I was okay with that, but I've added one more step to avoid it being passed in React props as well:

Screenshot 2024-10-24 at 2 25 45 PM

{...(hover ? theme.select.clear?.container?.hover : {})}
align={align}
>
<Text {...theme.select.clear.text}>{buttonLabel}</Text>
</Box>
)}
</StyledButton>
);
},
Expand Down
52 changes: 52 additions & 0 deletions src/js/components/Select/__tests__/Select-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1763,6 +1763,58 @@ describe('Select', () => {
expect(onChange.mock.calls[0][0].value.type).toBe(Box);
});

test('renders custom clear selection styling', () => {
jest.useFakeTimers();
const customTheme = {
select: {
clear: {
container: {
pad: {
vertical: '6px',
horizontal: '12px',
},
background: undefined,
hover: {
background: 'blue',
},
}, // any box props
text: {
color: 'text-strong',
weight: 600,
}, // any text props
},
},
};

const { asFragment, getByRole, getByPlaceholderText } = render(
<Grommet theme={customTheme}>
<Select
data-testid="test-select-style-open"
id="test-clear-selection"
options={['morning', 'afternoon', 'evening']}
placeholder="Select time"
value="afternoon"
clear
/>
</Grommet>,
);

expect(asFragment()).toMatchSnapshot();

fireEvent.click(getByPlaceholderText('Select time'));
act(() => {
jest.advanceTimersByTime(100);
});

const clearButton = getByRole('button', { name: /Clear selection/ });
expect(clearButton).toBeInTheDocument();
fireEvent.mouseOver(clearButton);
act(() => {
jest.advanceTimersByTime(200);
});
expectPortal('test-clear-selection__drop').toMatchSnapshot();
});

window.scrollTo.mockRestore();
window.HTMLElement.prototype.scrollIntoView.mockRestore();
});
Loading