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

Social links : Default background color problem fixed. Fix #34677 #34834

Closed

Conversation

HILAYTRIVEDI
Copy link
Contributor

@HILAYTRIVEDI HILAYTRIVEDI commented Sep 15, 2021

I tested the code with different themes which are default provided by WordPress. No other functionalities are affected by the changes. Two new useEffect() is added to the packages\block-library\src\social-links/edit.js for the default and pill classes. As in the pill also the same issue arises.

After the changes, I tested it with the different combinations of the use of the styling pattern, and it's working fine.

Video Demo Of Fix

https://www.awesomescreenshot.com/video/5232616?key=888676e6a53d9db85397b4430d64c810

Types of changes

The use effect in the file uses the previous state of the iconBackgroundColorValue and while the class changes it uses the value of preveIconBackgroundColorValue for the previously set value of the background.

Bug fix #34677

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.

@HILAYTRIVEDI HILAYTRIVEDI requested a review from mkaz as a code owner September 15, 2021 06:15
@github-actions
Copy link

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @HILAYTRIVEDI! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Sep 15, 2021
@HILAYTRIVEDI HILAYTRIVEDI marked this pull request as draft September 15, 2021 10:27
@HILAYTRIVEDI HILAYTRIVEDI marked this pull request as ready for review September 15, 2021 12:24
Copy link
Contributor

@stokesman stokesman left a comment

Choose a reason for hiding this comment

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

Hi @HILAYTRIVEDI, thanks taking this on. It looks like this resolves the issue. I think it'd better done without adding another block attribute because those are meant for things that need to persist across saves. Besides that, I think we can make this a bit simpler. I've left a couple of comments to elaborate but let me know if anything isn't clear.

packages/block-library/src/social-links/edit.js Outdated Show resolved Hide resolved
Copy link
Contributor

@stokesman stokesman left a comment

Choose a reason for hiding this comment

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

Thanks for the updates @HILAYTRIVEDI 👍 It's much nicer with the reduced changes. I've left some more feedback.

It'd be great to have another reviewer have a look but I see some others have been requested so I'll give them some time to get to it before pinging them again.

packages/block-library/src/social-links/edit.js Outdated Show resolved Hide resolved
packages/block-library/src/social-links/edit.js Outdated Show resolved Hide resolved
packages/block-library/src/social-links/block.json Outdated Show resolved Hide resolved
packages/block-library/src/social-links/edit.js Outdated Show resolved Hide resolved
@stokesman stokesman added the [Block] Social Affects the Social Block - used to display Social Media accounts label Sep 23, 2021
Copy link
Contributor

@stokesman stokesman left a comment

Choose a reason for hiding this comment

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

This works well in my testing and I've left one more suggestion but it seems optional. Perhaps another reviewer can weigh in on that. Either way, I think we could merge this. Thanks @HILAYTRIVEDI!

Comment on lines +78 to 91
backgroundBackup.current = {
iconBackgroundColor,
iconBackgroundColorValue,
customIconBackgroundColor,
};
setAttributes( {
iconBackgroundColor: undefined,
customIconBackgroundColor: undefined,
iconBackgroundColorValue: undefined,
} );
} else {
setAttributes( { ...backgroundBackup.current } );
}
}, [ logosOnly, setAttributes ] );
Copy link
Contributor

Choose a reason for hiding this comment

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

So this doesn't seem necessary (as mentioned before: #34834 (comment)) but it may be better to have all the consumed variables in the hook dependencies and it doesn't end up adding much complexity.

Suggested change
backgroundBackup.current = {
iconBackgroundColor,
iconBackgroundColorValue,
customIconBackgroundColor,
};
setAttributes( {
iconBackgroundColor: undefined,
customIconBackgroundColor: undefined,
iconBackgroundColorValue: undefined,
} );
} else {
setAttributes( { ...backgroundBackup.current } );
}
}, [ logosOnly, setAttributes ] );
setAttributes( {
iconBackgroundColor: undefined,
customIconBackgroundColor: undefined,
iconBackgroundColorValue: undefined,
} );
// Restore the attributes from backup on cleanup.
return () => setAttributes( { ...backgroundBackup.current } );
}
// Backup icon background attributes.
backgroundBackup.current = {
iconBackgroundColor,
iconBackgroundColorValue,
customIconBackgroundColor,
};
}, [
logosOnly,
setAttributes,
iconBackgroundColor,
iconBackgroundColorValue,
customIconBackgroundColor,
] );

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@stokesman I am happy that I get chance for contributing.

@Mamaduka
Copy link
Member

Hi, @HILAYTRIVEDI

Can you rebase this branch on top of the trunk? I think we can merge this once all checks are green.

@HILAYTRIVEDI
Copy link
Contributor Author

Hi @Mamaduka , I am unable to rebase the branch.

@gziolo gziolo removed their request for review January 13, 2022 11:36
@HILAYTRIVEDI HILAYTRIVEDI deleted the fix/34677-social-icons branch February 28, 2022 04:38
@HILAYTRIVEDI HILAYTRIVEDI restored the fix/34677-social-icons branch March 4, 2022 12:16
@HILAYTRIVEDI HILAYTRIVEDI deleted the fix/34677-social-icons branch March 4, 2022 12:16
@HILAYTRIVEDI HILAYTRIVEDI restored the fix/34677-social-icons branch March 7, 2022 04:56
@HILAYTRIVEDI HILAYTRIVEDI reopened this Mar 7, 2022
@HILAYTRIVEDI HILAYTRIVEDI reopened this Mar 8, 2022
@HILAYTRIVEDI HILAYTRIVEDI reopened this Mar 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Social Affects the Social Block - used to display Social Media accounts First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Social Icons: custom icon background colour does not persist when switching between block styles
3 participants