Skip to content

Commit 75ef017

Browse files
committed
Add configurable "Shift + Enter で改行" hint below AI overview input
Small muted gray helper text directly under the AI overview field, configurable via the block's hintText attribute (empty = hidden) and translatable. Wired to the textarea via aria-describedby. Hidden on touch devices via a device-capability media query (hover:none + pointer:coarse), deliberately not a width breakpoint. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RCRKyC4sroy5Xk144DGJdS
1 parent 305b9a2 commit 75ef017

5 files changed

Lines changed: 60 additions & 3 deletions

File tree

hamelp.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ function hamelp_render_search_box( $args = [] ) {
297297
*
298298
* @type string $placeholder Input placeholder text. Default 'Enter your question...'.
299299
* @type string $button_text Submit button text. Default 'Ask AI'.
300+
* @type string $hint_text Helper text shown below the input (empty = hidden). Default 'Shift + Enter で改行'.
300301
* @type bool $show_sources Whether to show source FAQ links. Default true.
301302
* @type string $wrapper_attrs Pre-built wrapper attributes string (used internally by block render).
302303
* }
@@ -313,6 +314,7 @@ function hamelp_render_ai_overview( $args = [] ) {
313314
[
314315
'placeholder' => __( 'Enter your question...', 'hamelp' ),
315316
'button_text' => __( 'Ask AI', 'hamelp' ),
317+
'hint_text' => __( 'Shift + Enter で改行', 'hamelp' ),
316318
'show_sources' => true,
317319
'wrapper_attrs' => '',
318320
]
@@ -352,23 +354,41 @@ function hamelp_render_ai_overview( $args = [] ) {
352354
);
353355
}
354356

357+
// Optional helper text below the field (e.g. "Shift + Enter で改行"). When set,
358+
// it is associated with the textarea via aria-describedby; empty = not rendered.
359+
$hint_text = trim( (string) $args['hint_text'] );
360+
$hint_html = '';
361+
$hint_attr = '';
362+
if ( '' !== $hint_text ) {
363+
$hint_id = wp_unique_id( 'hamelp-ai-overview-' ) . '-hint';
364+
$hint_html = sprintf(
365+
'<p class="hamelp-ai-overview__hint" id="%1$s">%2$s</p>',
366+
esc_attr( $hint_id ),
367+
esc_html( $hint_text )
368+
);
369+
$hint_attr = sprintf( ' aria-describedby="%s"', esc_attr( $hint_id ) );
370+
}
371+
355372
return sprintf(
356373
'<div %1$s>
357374
<div class="hamelp-ai-overview__thread" aria-live="polite"></div>
358375
<form class="hamelp-ai-overview__form">
359376
%2$s
360377
<div class="hamelp-ai-overview__input-row">
361-
<textarea class="hamelp-ai-overview__input" placeholder="%3$s" required></textarea>
378+
<textarea class="hamelp-ai-overview__input" placeholder="%3$s"%5$s required></textarea>
362379
<button type="submit" class="hamelp-ai-overview__button">
363380
<svg class="hamelp-ai-overview__button-icon" width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true" focusable="false" xmlns="http://www.w3.org/2000/svg"><path d="M12 19V5M6 11l6-6 6 6" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>
364381
<span class="screen-reader-text">%4$s</span>
365382
</button>
366383
</div>
384+
%6$s
367385
</form>
368386
</div>',
369387
$args['wrapper_attrs'],
370388
$continue_toggle, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- built from esc_html__ above.
371389
esc_attr( $args['placeholder'] ),
372-
esc_html( $args['button_text'] )
390+
esc_html( $args['button_text'] ),
391+
$hint_attr, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- built from esc_attr above.
392+
$hint_html // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- built from esc_html/esc_attr above.
373393
);
374394
}

src/blocks/ai-overview/block.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
"type": "string",
1717
"default": "Ask AI"
1818
},
19+
"hintText": {
20+
"type": "string",
21+
"default": "Shift + Enter で改行"
22+
},
1923
"showSources": {
2024
"type": "boolean",
2125
"default": true

src/blocks/ai-overview/edit.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { PanelBody, TextControl, ToggleControl } from '@wordpress/components';
1717
* @return {JSX.Element} Block editor component.
1818
*/
1919
export default function Edit( { attributes, setAttributes } ) {
20-
const { placeholder, buttonText, showSources } = attributes;
20+
const { placeholder, buttonText, hintText, showSources } = attributes;
2121

2222
return (
2323
<>
@@ -44,6 +44,17 @@ export default function Edit( { attributes, setAttributes } ) {
4444
setAttributes( { buttonText: value } )
4545
}
4646
/>
47+
<TextControl
48+
label={ __( '入力欄下の補助テキスト', 'hamelp' ) }
49+
help={ __(
50+
'Shift+Enterで改行できることの案内などに。空にすると非表示。スマートフォン等のタッチ端末では自動的に非表示になります。',
51+
'hamelp'
52+
) }
53+
value={ hintText }
54+
onChange={ ( value ) =>
55+
setAttributes( { hintText: value } )
56+
}
57+
/>
4758
<ToggleControl
4859
label={ __( 'Show Sources', 'hamelp' ) }
4960
checked={ showSources }
@@ -80,6 +91,9 @@ export default function Edit( { attributes, setAttributes } ) {
8091
</span>
8192
</button>
8293
</div>
94+
{ hintText && (
95+
<p className="hamelp-ai-overview__hint">{ hintText }</p>
96+
) }
8397
<p className="hamelp-ai-overview__note">
8498
{ __( 'AI Overview - Preview', 'hamelp' ) }
8599
</p>

src/blocks/ai-overview/render.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
[
2424
'placeholder' => $attributes['placeholder'] ?? __( 'Enter your question...', 'hamelp' ),
2525
'button_text' => $attributes['buttonText'] ?? __( 'Ask AI', 'hamelp' ),
26+
'hint_text' => $attributes['hintText'] ?? __( 'Shift + Enter で改行', 'hamelp' ),
2627
'show_sources' => ! empty( $attributes['showSources'] ),
2728
'wrapper_attrs' => $wrapper_attributes,
2829
]

src/blocks/ai-overview/style.scss

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,24 @@
109109
outline-offset: 2px;
110110
}
111111

112+
// Small muted helper text directly under the input (e.g. "Shift + Enter で改行").
113+
// Muted via opacity so it inherits and adapts to any theme's text color.
114+
:where(.hamelp-ai-overview__hint) {
115+
margin: 0.375rem 0 0 0.75rem;
116+
font-size: 0.8em;
117+
line-height: 1.4;
118+
opacity: 0.6;
119+
}
120+
121+
// Hide the hint on touch devices, where Shift+Enter is meaningless without a
122+
// physical keyboard. Device-CAPABILITY query (coarse pointer + no hover),
123+
// deliberately NOT a width breakpoint, to avoid colliding with theme breakpoints.
124+
@media (hover: none) and (pointer: coarse) {
125+
:where(.hamelp-ai-overview__hint) {
126+
display: none;
127+
}
128+
}
129+
112130
:where(.hamelp-ai-overview__button) {
113131
// Fixed-size circular icon button (ChatGPT-style), floated inside the field's
114132
// bottom-right corner. The constant bottom offset keeps it pinned to the

0 commit comments

Comments
 (0)