Skip to content

fix(components): [config-provider] preserve zero zIndex#24331

Merged
btea merged 3 commits into
element-plus:devfrom
guozi9999:fix/config-zindex-zero
May 29, 2026
Merged

fix(components): [config-provider] preserve zero zIndex#24331
btea merged 3 commits into
element-plus:devfrom
guozi9999:fix/config-zindex-zero

Conversation

@guozi9999
Copy link
Copy Markdown
Contributor

@guozi9999 guozi9999 commented May 26, 2026

Please make sure these boxes are checked before submitting your PR, thank you!

  • Make sure you follow contributing guide English | (中文 | Español | Français).
  • Make sure you are merging your commits to dev branch.
  • Add some descriptions and refer to relative issues for your PR.

Summary

fix: #24330

  • Preserve 0 as a valid global z-index value.
  • Add a regression test for ConfigProvider zIndex={0}.

Problem

useGlobalComponentSettings used || to fall back to defaultInitialZIndex:

computed(() => config.value?.zIndex || defaultInitialZIndex)

This caused 0 to be treated as missing because 0 is falsy.

Solution

Use ?? so only null or undefined fall back to the default:

computed(() => config.value?.zIndex ?? defaultInitialZIndex)

Summary by CodeRabbit

  • Bug Fixes

    • ConfigProvider now correctly treats an explicit zIndex of 0 as valid and only falls back to the default initial z-index for missing or invalid numeric values (e.g., NaN), preventing accidental overrides from falsy values.
  • Tests

    • Added tests verifying explicit zIndex=0 is preserved and that invalid/missing zIndex values fall back to the default.

Review Change Stack

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 26, 2026

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 26, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4f43dbf9-d8ca-4a7b-9669-c3f52d91d0bf

📥 Commits

Reviewing files that changed from the base of the PR and between 1a4a65f and 9b57f8a.

📒 Files selected for processing (1)
  • packages/components/config-provider/src/hooks/use-global-config.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/components/config-provider/src/hooks/use-global-config.ts

📝 Walkthrough

Walkthrough

Compute logic for global component zIndex now treats 0 as a valid configured value and falls back to defaultInitialZIndex only when zIndex is null/undefined or NaN. Tests were added verifying that zIndex={0} is preserved and zIndex={Number.NaN} falls back to defaultInitialZIndex.

Changes

Z-Index handling fix and tests

Layer / File(s) Summary
Explicit zIndex null/NaN check
packages/components/config-provider/src/hooks/use-global-config.ts
Changed zIndex fallback from a `
Tests for zero and NaN zIndex
packages/components/config-provider/__tests__/config-provider.test.tsx
Updated imports to include defaultInitialZIndex and added tests verifying useGlobalComponentSettings('button') yields initialZIndex of 0 when ConfigProvider sets zIndex={0}, and falls back to defaultInitialZIndex when zIndex={Number.NaN}.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

A rabbit nibbles through the code, 🐰
Counting zeros, not a single one to goad,
It finds NaN and says "fallback, please,"
But lets 0 sit proudly as the zIndex breeze. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: fixing the config-provider to preserve zero as a valid zIndex value.
Description check ✅ Passed The description includes a clear summary with problem statement, solution, and references the linked issue #24330. It explains the root cause and the fix.
Linked Issues check ✅ Passed The PR successfully addresses issue #24330 by replacing the || operator with ?? (nullish coalescing) in useGlobalComponentSettings to preserve 0 as valid zIndex, and adds a regression test.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the zIndex=0 preservation issue: the hook logic change, test cases, and imports of isNil utility are all in scope.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 26, 2026

Open in StackBlitz

pnpm add https://pkg.pr.new/element-plus@24331
npm i https://pkg.pr.new/element-plus@24331
yarn add https://pkg.pr.new/[email protected]

commit: 9b57f8a

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1857622971

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/components/config-provider/src/hooks/use-global-config.ts Outdated
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 26, 2026

🧪 Playground Preview: https://element-plus.run/?pr=24331
Please comment the example via this playground if needed.

@guozi9999 guozi9999 changed the title fix(components): [time-select] guard invalid time values fix(components): [config-provider] preserve zero zIndex May 26, 2026
Comment thread packages/components/config-provider/src/hooks/use-global-config.ts Outdated
@guozi9999
Copy link
Copy Markdown
Contributor Author

I've made the requested changes. Please review when convenient. Thanks!

@btea btea merged commit 951afc1 into element-plus:dev May 29, 2026
17 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

@guozi9999 Thanks for your contribution! ❤️

@element-bot element-bot mentioned this pull request May 29, 2026
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Component] [config-provider] ConfigProvider ignores zIndex set to 0

3 participants