Skip to content
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
1 change: 1 addition & 0 deletions UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- Fixed focus state color on monochrome `Buttons` ([#2684](https://github.com/Shopify/polaris-react/pull/2684))
- Fixed container's width on `Modal` ([#2692](https://github.com/Shopify/polaris-react/pull/2692))
- Fixed the position property for the backdrop on `Select` from being overwritten by the focus ring ([#2748](https://github.com/Shopify/polaris-react/pull/2748))
- Fixed `ResourceItem` `Actions` visibility on mouse out ([#2742](https://github.com/Shopify/polaris-react/pull/2742))

### Documentation

Expand Down
8 changes: 7 additions & 1 deletion src/components/ResourceItem/ResourceItem.scss
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ $resource-list-item-variables: (
outline: none;
cursor: pointer;

&:not(.persistActions) {
// stylelint-disable-next-line selector-max-combinators
.Actions {
right: spacing();
}
}

&:hover {
&:not(.newDesignLanguage) {
background-image: linear-gradient(
Expand All @@ -51,7 +58,6 @@ $resource-list-item-variables: (
// stylelint-disable-next-line selector-max-specificity
.Actions {
@include action-unhide;
right: spacing();

// stylelint-disable-next-line max-nesting-depth
@include page-content-when-partially-condensed {
Expand Down
5 changes: 5 additions & 0 deletions src/components/ResourceItem/ResourceItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ class BaseResourceItem extends React.Component<CombinedProps, State> {
onFocus={this.handleFocus}
onBlur={this.handleBlur}
onKeyUp={this.handleKeyUp}
onMouseOut={this.handleMouseOut}
testID="Item-Wrapper"
data-href={url}
>
Expand Down Expand Up @@ -342,6 +343,10 @@ class BaseResourceItem extends React.Component<CombinedProps, State> {
this.setState({focused: false, focusedInner: false});
};

private handleMouseOut = () => {
this.state.focused && this.setState({focused: false, focusedInner: false});
};

private handleLargerSelectionArea = (event: React.MouseEvent<any>) => {
stopPropagation(event);
this.handleSelection(!this.state.selected, event.nativeEvent.shiftKey);
Expand Down
25 changes: 25 additions & 0 deletions src/components/ResourceItem/tests/ResourceItem.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,31 @@ describe('<ResourceItem />', () => {
});
});
});

describe('focused', () => {
it('removes the focus state when mousing out a focused item', () => {
const resourceItem = mountWithApp(
<ResourceListContext.Provider value={mockSelectModeContext}>
<ResourceItem id={itemId} url={url} />
</ResourceListContext.Provider>,
);
const wrapperDiv = resourceItem.find('div');

wrapperDiv!.trigger('onFocus', {
target: wrapperDiv!.domNode as HTMLDivElement,
});

expect(resourceItem).toContainReactComponent('div', {
className: 'ResourceItem focused selectable selectMode focusedInner',
});

wrapperDiv!.trigger('onMouseOut');

expect(resourceItem).toContainReactComponent('div', {
className: 'ResourceItem selectable selectMode',
});
});
});
});

function noop() {}