File tree Expand file tree Collapse file tree 3 files changed +43
-7
lines changed Expand file tree Collapse file tree 3 files changed +43
-7
lines changed Original file line number Diff line number Diff line change @@ -173,7 +173,11 @@ The `Hint` component can be used to wrap custom inputs.
173173#### Props
174174Name | Type | Default | Description
175175-----|------|---------|------------
176- children ` (required) ` | node | |
176+ children ` (required) ` | ` ReactNode ` | |
177+ className | ` string ` | Class names applied to the containing element. |
178+ hintClassName | ` string ` | Class names applied to the the hint element. |
179+ hintStyle | ` CSSProperties ` | Inline styles applied to the hint element. |
180+ style | ` CSSProperties ` | Inline styl;es applied to the containing element. |
177181
178182### ` <Input> `
179183Abstract ` <input> ` component that handles an ` inputRef ` prop and is used as the basis for both single- and multi-select input components.
Original file line number Diff line number Diff line change 1+ import * as React from 'react' ;
2+
13import * as stories from './Hint.stories' ;
2- import { generateSnapshots } from '../../tests/helpers' ;
4+ import {
5+ composeStories ,
6+ generateSnapshots ,
7+ render ,
8+ screen ,
9+ } from '../../tests/helpers' ;
10+
11+ const { Default } = composeStories ( stories ) ;
312
413describe ( '<Hint>' , ( ) => {
514 generateSnapshots ( stories ) ;
15+
16+ it ( 'applies a classname and style to the containing element' , ( ) => {
17+ const { container } = render (
18+ < Default className = "custom-class" style = { { backgroundColor : 'blue' } } />
19+ ) ;
20+
21+ expect ( container . firstChild ) . toHaveClass ( 'custom-class' ) ;
22+ expect ( container . firstChild ) . toHaveStyle ( { backgroundColor : 'blue' } ) ;
23+ } ) ;
24+
25+ it ( 'applies a classname and style to the hint element' , ( ) => {
26+ render ( < Default hintClassName = "hint-class" hintStyle = { { color : 'red' } } /> ) ;
27+
28+ const hintElement = screen . getByDisplayValue ( 'california' ) ;
29+ expect ( hintElement ) . toHaveClass ( 'hint-class' ) ;
30+ expect ( hintElement ) . toHaveStyle ( { color : 'red' } ) ;
31+ } ) ;
632} ) ;
Original file line number Diff line number Diff line change 1- import React , { ReactNode } from 'react' ;
1+ import cx from 'classnames' ;
2+ import React , { CSSProperties , ReactNode } from 'react' ;
23
34import { useHint } from '../../hooks' ;
45
56export interface HintProps {
67 children : ReactNode ;
78 className ?: string ;
9+ hintClassName ?: string ;
10+ hintStyle ?: CSSProperties ;
11+ style ?: CSSProperties ;
812}
913
10- const Hint = ( { children , className } : HintProps ) => {
14+ const Hint = ( props : HintProps ) => {
1115 const { hintRef, hintText } = useHint ( ) ;
1216
1317 return (
1418 < div
15- className = { className }
19+ className = { props . className }
1620 style = { {
1721 display : 'flex' ,
1822 flex : 1 ,
1923 height : '100%' ,
2024 position : 'relative' ,
25+ ...props . style ,
2126 } } >
22- { children }
27+ { props . children }
2328 < input
2429 aria-hidden
25- className = " rbt-input-hint"
30+ className = { cx ( ' rbt-input-hint' , props . hintClassName ) }
2631 ref = { hintRef }
2732 readOnly
2833 style = { {
@@ -35,6 +40,7 @@ const Hint = ({ children, className }: HintProps) => {
3540 position : 'absolute' ,
3641 top : 0 ,
3742 width : '100%' ,
43+ ...props . hintStyle ,
3844 } }
3945 tabIndex = { - 1 }
4046 value = { hintText }
You can’t perform that action at this time.
0 commit comments