Skip to content

Commit

Permalink
Merge pull request #16535 from craftcms/bugfix/16528-prevent-autofocu…
Browse files Browse the repository at this point in the history
…s-on-t9n-and-action-menu-btn

prevent autofocus on t9n and action menu btn
  • Loading branch information
brandonkelly authored Jan 27, 2025
2 parents bdb0ca5 + c68b445 commit 73e69ee
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
- Fixed JavaScript error that occurred if there was problem sending a password-reset email.
- Fixed an error that could occur when working with an entry whose type is no longer allowed by its section/field. ([#16539](https://github.com/craftcms/cms/issues/16539))
- Fixed a bug where tooltips were displaying behind slideouts. ([#16529](https://github.com/craftcms/cms/issues/16529))
- Fixed a bug where field translation indicators and action menu buttons could be autofocussed when creating a new entry within a Matrix field, or opening an element editor slideout. ([#16528](https://github.com/craftcms/cms/issues/16528))

## 5.6.1 - 2025-01-22

Expand Down
4 changes: 2 additions & 2 deletions src/helpers/Cp.php
Original file line number Diff line number Diff line change
Expand Up @@ -1532,7 +1532,7 @@ public static function fieldHtml(string|callable $input, array $config = []): st

$translationDescription = $config['translationDescription'] ?? Craft::t('app', 'This field is translatable.');
$translationIconHtml = Html::button('', [
'class' => ['t9n-indicator'],
'class' => ['t9n-indicator', 'prevent-autofocus'],
'data' => [
'icon' => 'language',
],
Expand Down Expand Up @@ -1610,7 +1610,7 @@ public static function fieldHtml(string|callable $input, array $config = []): st
($showActionMenu ? static::disclosureMenu($config['actionMenuItems'], [
'hiddenLabel' => Craft::t('app', 'Actions'),
'buttonAttributes' => [
'class' => ['action-btn', 'small'],
'class' => ['action-btn', 'small', 'prevent-autofocus'],
],
]) : '') .
($showAttribute ? static::renderTemplate('_includes/forms/copytextbtn.twig', [
Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/matrix/dist/MatrixInput.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/matrix/dist/MatrixInput.js.map

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion src/web/assets/matrix/src/MatrixInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,11 @@
// Scroll to the entry
Garnish.scrollContainerToElement($entry);
// Focus on the first focusable element
$entry.find('.flex-fields :focusable').first().focus();
$entry
.find('.flex-fields :focusable')
.not('.prevent-autofocus')
.first()
.focus();
}

// Resume the element editor
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/helpers/CpHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function testFieldHtml(): void
self::assertStringContainsString('aria-labelledby="', $fieldset);
self::assertStringContainsString('role="group"', $fieldset);
// translatable
self::assertStringContainsString('class="t9n-indicator"', Cp::fieldHtml('<input>', ['label' => 'Label', 'translatable' => true]));
self::assertStringContainsString('class="t9n-indicator prevent-autofocus"', Cp::fieldHtml('<input>', ['label' => 'Label', 'translatable' => true]));
// instructions
$withInstructions = Cp::fieldHtml('<input>', ['instructionsId' => 'inst-id', 'instructions' => '**Test**']);
self::assertStringContainsString('id="inst-id"', $withInstructions);
Expand Down

0 comments on commit 73e69ee

Please sign in to comment.