@@ -6,9 +6,10 @@ import { useState } from "react";
66import DxcSearchBar from "./SearchBar" ;
77import DxcFlex from "../flex/Flex" ;
88import DxcContainer from "../container/Container" ;
9+ import { userEvent , within } from "storybook/internal/test" ;
910
1011export default {
11- title : "Searchbar " ,
12+ title : "Search Bar " ,
1213 component : DxcSearchBar ,
1314} satisfies Meta < typeof DxcSearchBar > ;
1415
@@ -21,7 +22,6 @@ const SearchBarComponent = () => {
2122 < DxcSearchBarTrigger onTriggerClick = { ( ) => setShowSearch ( ! showSearch ) } />
2223 ) : (
2324 < DxcSearchBar
24- placeholder = "Search..."
2525 onBlur = { ( value ) => {
2626 console . log ( "onBlur" , value ) ;
2727 } }
@@ -40,14 +40,15 @@ const SearchBarComponent = () => {
4040const SearchBar = ( ) => {
4141 return (
4242 < >
43- < Title title = "Searchbar component" theme = "light" level = { 2 } />
43+ < Title title = "Search Bar component" theme = "light" level = { 2 } />
4444 < ExampleContainer >
4545 < SearchBarComponent />
4646 </ ExampleContainer >
4747
4848 < Title title = "States" theme = "light" level = { 2 } />
4949 < ExampleContainer >
5050 < Title title = "Default" theme = "light" level = { 4 } />
51+ < DxcSearchBarTrigger onTriggerClick = { ( ) => { } } />
5152 < DxcSearchBar
5253 placeholder = "Search..."
5354 onBlur = { ( value ) => {
@@ -57,10 +58,12 @@ const SearchBar = () => {
5758 onEnter = { ( value ) => {
5859 console . log ( "onEnter" , value ) ;
5960 } }
61+ onCancel = { ( ) => { } }
6062 />
6163 </ ExampleContainer >
6264 < ExampleContainer pseudoState = "pseudo-hover" >
6365 < Title title = "Hover" theme = "light" level = { 4 } />
66+ < DxcSearchBarTrigger onTriggerClick = { ( ) => { } } />
6467 < DxcSearchBar
6568 placeholder = "Search..."
6669 onBlur = { ( value ) => {
@@ -70,10 +73,27 @@ const SearchBar = () => {
7073 onEnter = { ( value ) => {
7174 console . log ( "onEnter" , value ) ;
7275 } }
76+ onCancel = { ( ) => { } }
7377 />
7478 </ ExampleContainer >
75- < ExampleContainer pseudoState = "pseudo-focus- within" >
79+ < ExampleContainer pseudoState = { [ "pseudo-focus" , "pseudo-focus- within"] } >
7680 < Title title = "Focus" theme = "light" level = { 4 } />
81+ < DxcSearchBarTrigger onTriggerClick = { ( ) => { } } />
82+ < DxcSearchBar
83+ placeholder = "Search..."
84+ onBlur = { ( value ) => {
85+ console . log ( "onBlur" , value ) ;
86+ } }
87+ onChange = { ( value ) => console . log ( "onChange" , value ) }
88+ onEnter = { ( value ) => {
89+ console . log ( "onEnter" , value ) ;
90+ } }
91+ onCancel = { ( ) => { } }
92+ />
93+ </ ExampleContainer >
94+ < ExampleContainer pseudoState = { [ "pseudo-focus" , "pseudo-active" ] } >
95+ < Title title = "Focus and active" theme = "light" level = { 4 } />
96+ < DxcSearchBarTrigger onTriggerClick = { ( ) => { } } />
7797 < DxcSearchBar
7898 placeholder = "Search..."
7999 onBlur = { ( value ) => {
@@ -83,6 +103,7 @@ const SearchBar = () => {
83103 onEnter = { ( value ) => {
84104 console . log ( "onEnter" , value ) ;
85105 } }
106+ onCancel = { ( ) => { } }
86107 />
87108 </ ExampleContainer >
88109 < ExampleContainer >
@@ -96,6 +117,7 @@ const SearchBar = () => {
96117 onEnter = { ( value ) => {
97118 console . log ( "onEnter" , value ) ;
98119 } }
120+ onCancel = { ( ) => { } }
99121 disabled
100122 />
101123 </ ExampleContainer >
@@ -123,4 +145,14 @@ type Story = StoryObj<typeof DxcSearchBar>;
123145
124146export const Chromatic : Story = {
125147 render : SearchBar ,
148+ play : async ( { canvasElement } ) => {
149+ const canvas = within ( canvasElement ) ;
150+ const user = userEvent . setup ( ) ;
151+
152+ const enabledInputs = ( await canvas . findAllByRole ( "textbox" ) ) . filter ( ( input ) => ! input . hasAttribute ( "disabled" ) ) ;
153+
154+ for ( let i = 0 ; i < enabledInputs . length - 1 ; i ++ ) {
155+ await user . type ( enabledInputs [ i ] ! , "Lorem ipsum" ) ;
156+ }
157+ } ,
126158} ;
0 commit comments