Skip to content

Prevent layout shift on hover in libs/board manager #1568

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

Merged
merged 3 commits into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,14 @@ export class ComponentListItem<
)[0];
this.state = {
selectedVersion: version,
focus: false,
versionUpdate: false,
};
}
}

override componentDidUpdate(
prevProps: ComponentListItem.Props<T>,
prevState: ComponentListItem.State
): void {
if (this.state.focus !== prevState.focus) {
this.props.onFocusDidChange();
}
}

override render(): React.ReactNode {
const { item, itemRenderer } = this.props;
return (
<div
onMouseEnter={() => this.setState({ focus: true })}
onMouseLeave={() => {
if (!this.state.versionUpdate) this.setState({ focus: false });
}}
>
<div>
Copy link
Contributor

Choose a reason for hiding this comment

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

Having a div here is superfluous at this point. Please replace it with a react fragment (<>...</>).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I replaced it here. Thanks 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

even the fragment is superfluous we can just return the node no?

return itemRenderer.renderItem(
    Object.assign(this.state, { item }),
    this.install.bind(this),
    this.uninstall.bind(this),
    this.onVersionChange.bind(this)
);

{itemRenderer.renderItem(
Object.assign(this.state, { item }),
this.install.bind(this),
Expand All @@ -55,7 +39,6 @@ export class ComponentListItem<
)[0];
this.setState({
selectedVersion: version,
versionUpdate: false,
});
try {
await this.props.install(item, toInstall);
Expand All @@ -71,7 +54,7 @@ export class ComponentListItem<
}

private onVersionChange(version: Installable.Version): void {
this.setState({ selectedVersion: version, versionUpdate: true });
this.setState({ selectedVersion: version });
}
}

Expand All @@ -81,12 +64,9 @@ export namespace ComponentListItem {
readonly install: (item: T, version?: Installable.Version) => Promise<void>;
readonly uninstall: (item: T) => Promise<void>;
readonly itemRenderer: ListItemRenderer<T>;
readonly onFocusDidChange: () => void;
}

export interface State {
selectedVersion?: Installable.Version;
focus: boolean;
versionUpdate: boolean;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export class ComponentList<T extends ArduinoComponent> extends React.Component<
rowIndex={index}
parent={parent}
>
{({ measure, registerChild }) => (
{({ registerChild }) => (
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
<div ref={registerChild} style={style}>
Expand All @@ -135,7 +135,6 @@ export class ComponentList<T extends ArduinoComponent> extends React.Component<
itemRenderer={this.props.itemRenderer}
install={this.props.install}
uninstall={this.props.uninstall}
onFocusDidChange={() => measure()}
/>
</div>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class ListItemRenderer<T extends ArduinoComponent> {
uninstall: (item: T) => Promise<void>,
onVersionChange: (version: Installable.Version) => void
): React.ReactNode {
const { item, focus } = input;
const { item } = input;
let nameAndAuthor: JSX.Element;
if (item.name && item.author) {
const name = <span className="name">{item.name}</span>;
Expand Down Expand Up @@ -127,12 +127,10 @@ export class ListItemRenderer<T extends ArduinoComponent> {
{description}
</div>
<div className="info">{moreInfo}</div>
{focus && (
<div className="footer">
{versions}
{installButton}
</div>
)}
<div className="footer">
{versions}
{installButton}
</div>
</div>
);
}
Expand Down