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

Fixes the default fluid value on the UI based on the global typography fluid value. #64803

Merged
merged 1 commit into from
Aug 27, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,17 @@ function FontSize() {
'typography.fontSizes'
);

const [ globalFluid ] = useGlobalSetting( 'typography.fluid' );

// Get the font sizes from the origin, default to empty array.
const sizes = fontSizes[ origin ] ?? [];

// Get the font size by slug.
const fontSize = sizes.find( ( size ) => size.slug === slug );

// Whether fluid is true or an object, set it to true, otherwise false.
const isFluid = !! fontSize.fluid ?? false;
// Whether the font size is fluid. If not defined, use the global fluid value of the theme.
const isFluid =
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for the late review. I noticed that it was already merged, but I'll comment just in case.

settings.typography.fluid is not necessarily a boolean value, but can be an object. That is, if the following theme.json is defined, isFluid will be an object:

{
	"settings": {
		"typography": {
			"fluid": {
				"minFontSize": "16px"
			},
			"fontSizes": [
				{
					"name": "Theme font size 1",
					"size": "30px",
					"slug": "theme-1"
				}
			]
		}
	},
	"version": 3
}

We might want to change it to the following to ensure that isFluid is always a boolean value:

fontSize.fluid !== undefined ? !! fontSize.fluid : !! globalFluid;

However, the current implementation works fine for now.

Copy link
Member

Choose a reason for hiding this comment

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

Good point, thanks for catching.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for noticing that @t-hamano.
I submitted the fix: #64882

fontSize.fluid !== undefined ? !! fontSize.fluid : globalFluid;

// Whether custom fluid values are used.
const isCustomFluid = typeof fontSize.fluid === 'object';
Expand Down
Loading