Skip to content

Commit 05d3b3c

Browse files
committed
KSES: Allow the autofocus attribute on dialog elements.
First step to allow the usage of the autofocus attribute for native dialog elements. More work will follow to add a context-aware mechanism to KSES and allow the attribute on dialog element children. Props westonruter, joedolson, mukesh27, afercia. Fixes #65491. git-svn-id: https://develop.svn.wordpress.org/trunk@62850 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 07b1f8b commit 05d3b3c

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

‎src/wp-includes/kses.php‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,10 @@
158158
'popover' => true,
159159
),
160160
'dialog' => array(
161-
'closedby' => true,
162-
'open' => true,
163-
'popover' => true,
161+
'closedby' => true,
162+
'open' => true,
163+
'popover' => true,
164+
'autofocus' => true,
164165
),
165166
'dl' => array(),
166167
'dt' => array(),

‎tests/phpunit/tests/kses.php‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2183,6 +2183,18 @@ public function test_wp_kses_main_tag_standard_attributes() {
21832183
$this->assertEqualHTML( $html, wp_kses_post( $html ) );
21842184
}
21852185

2186+
/**
2187+
* Tests that the autofocus attribute is allowed on dialog elements and removed from other focusable elements.
2188+
*
2189+
* @ticket 65491
2190+
*/
2191+
public function test_wp_kses_dialog_autofocus_attribute() {
2192+
$html = '<dialog open autofocus>Content</dialog><button type="button" autofocus>Button</button><textarea autofocus>Some content</textarea><div tabindex="0" autofocus>Some content</div>';
2193+
$expected = '<dialog open autofocus>Content</dialog><button type="button">Button</button><textarea>Some content</textarea><div tabindex="0">Some content</div>';
2194+
2195+
$this->assertEqualHTML( $expected, wp_kses_post( $html ) );
2196+
}
2197+
21862198
/**
21872199
* Test that Invoker Commands API attributes are preserved on buttons in post content.
21882200
*

0 commit comments

Comments
 (0)