Skip to content

fix(autofocus): ensure autofocus attribute is not set when left undefined - #1401

Open
marmotz wants to merge 1 commit into
openng-org:mainfrom
marmotz:240-autofocus-undefined-false
Open

fix(autofocus): ensure autofocus attribute is not set when left undefined#1401
marmotz wants to merge 1 commit into
openng-org:mainfrom
marmotz:240-autofocus-undefined-false

Conversation

@marmotz

@marmotz marmotz commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes the AutoFocus directive (pAutoFocus), which is used internally by Button, DatePicker, MultiSelect, RadioButton, Select, Slider, and the table's p-columnFilter menu button.

The directive removed the native autofocus DOM attribute only when its input was strictly === false. Since several host components declare their own autofocus input as boolean | undefined with no explicit default, the value passed down is undefined rather than false, which the strict check did not catch (causing the autofocus attribute to be set unintentionally whenever the consumer left autofocus unset).

Before: any of the affected components (e.g. p-datepicker, p-select, the first p-columnFilter menu button in a table) received autofocus="true" by default.
After: the directive uses a falsy check (!this.autofocus), so the attribute is only set when autofocus is explicitly truthy.

Related issues

Fixes #240

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that changes the public API)
  • Documentation only
  • Refactor, test, or chore (no user-facing change)

Breaking changes

None

Test plan

  • npm run build
  • npm test
  • npm run lint
  • Verified in the demo app (if applicable)

Checklist

  • Issue discussed or bug clearly described (link issue when applicable)
  • Tests added or updated for behavioral changes
  • Documentation updated (README, JSDoc, migration notes as needed)
  • Public API changes documented; breaking changes called out
  • CHANGELOG updated (if the repository maintains one and the change is user-facing)
  • Commit messages follow Conventional Commits
  • I agree to follow the OpenNG Foundation Code of Conduct

Additional context

Root cause and originally suggested fix (!this.autofocus instead of this.autofocus === false) were identified in the issue comments by @sakonn (patch-package workaround) and @WolfspiritM (traced the bug to button.ts's [pAutoFocus]="autofocus || buttonProps?.autofocus" evaluating to undefined).
This also resolves the related p-columnFilter first-filter auto-selection behavior reported in the same thread.

The generated docs currently list false as the default for autofocus on the affected components, but the actual source declares it as boolean | undefined with no explicit default (this pre-existing doc/code mismatch is unrelated to this fix and left untouched here).

@marmotz
marmotz force-pushed the 240-autofocus-undefined-false branch 6 times, most recently from e8506d5 to 3736dc3 Compare July 26, 2026 08:17
@geromegrignon geromegrignon added this to the Catch-up milestone Jul 26, 2026
@marmotz
marmotz force-pushed the 240-autofocus-undefined-false branch from 3736dc3 to 363a789 Compare July 31, 2026 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

p-datepicker gets autofocus when autofocus property is not set

2 participants