fix(autofocus): ensure autofocus attribute is not set when left undefined - #1401
Open
marmotz wants to merge 1 commit into
Open
fix(autofocus): ensure autofocus attribute is not set when left undefined#1401marmotz wants to merge 1 commit into
marmotz wants to merge 1 commit into
Conversation
marmotz
force-pushed
the
240-autofocus-undefined-false
branch
6 times, most recently
from
July 26, 2026 08:17
e8506d5 to
3736dc3
Compare
…ined # Conflicts: # pnpm-lock.yaml
marmotz
force-pushed
the
240-autofocus-undefined-false
branch
from
July 31, 2026 16:23
3736dc3 to
363a789
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes the
AutoFocusdirective (pAutoFocus), which is used internally byButton,DatePicker,MultiSelect,RadioButton,Select,Slider, and the table'sp-columnFiltermenu button.The directive removed the native
autofocusDOM attribute only when its input was strictly=== false. Since several host components declare their ownautofocusinput asboolean | undefinedwith no explicit default, the value passed down isundefinedrather thanfalse, which the strict check did not catch (causing theautofocusattribute to be set unintentionally whenever the consumer leftautofocusunset).Before: any of the affected components (e.g.
p-datepicker,p-select, the firstp-columnFiltermenu button in a table) receivedautofocus="true"by default.After: the directive uses a falsy check (
!this.autofocus), so the attribute is only set whenautofocusis explicitly truthy.Related issues
Fixes #240
Type of change
Breaking changes
None
Test plan
npm run buildnpm testnpm run lintChecklist
Additional context
Root cause and originally suggested fix (
!this.autofocusinstead ofthis.autofocus === false) were identified in the issue comments by@sakonn(patch-package workaround) and@WolfspiritM(traced the bug tobutton.ts's[pAutoFocus]="autofocus || buttonProps?.autofocus"evaluating toundefined).This also resolves the related
p-columnFilterfirst-filter auto-selection behavior reported in the same thread.The generated docs currently list
falseas the default for autofocus on the affected components, but the actual source declares it asboolean | undefinedwith no explicit default (this pre-existing doc/code mismatch is unrelated to this fix and left untouched here).