Skip to content

Commit f3f7c37

Browse files
Merge pull request LucasBassetti#119 from Cyclodex/PR-inputSupportAutofill
Chatbot input field: Support overriding of individual attributes per steps
2 parents cc60950 + a0bdee0 commit f3f7c37

File tree

9 files changed

+69
-1
lines changed

9 files changed

+69
-1
lines changed

dist/react-simple-chatbot.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/ChatBot.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@ class ChatBot extends Component {
527527
hideSubmitButton,
528528
inputStyle,
529529
placeholder,
530+
inputAttributes,
530531
recognitionPlaceholder,
531532
style,
532533
submitButtonStyle,
@@ -551,6 +552,8 @@ class ChatBot extends Component {
551552
const inputPlaceholder = speaking ? recognitionPlaceholder :
552553
currentStep.placeholder || placeholder;
553554

555+
const inputAttributesOverride = currentStep.inputAttributes || inputAttributes;
556+
554557
return (
555558
<div className={`rsc ${className}`}>
556559
{floating && (
@@ -596,6 +599,7 @@ class ChatBot extends Component {
596599
invalid={inputInvalid}
597600
disabled={disabled}
598601
hasButton={!hideSubmitButton}
602+
{...inputAttributesOverride}
599603
/>
600604
)}
601605
{!currentStep.hideInput && !hideSubmitButton && (
@@ -643,6 +647,7 @@ ChatBot.propTypes = {
643647
opened: PropTypes.bool,
644648
toggleFloating: PropTypes.func,
645649
placeholder: PropTypes.string,
650+
inputAttributes: PropTypes.object,
646651
recognitionEnable: PropTypes.bool,
647652
recognitionLang: PropTypes.string,
648653
recognitionPlaceholder: PropTypes.string,
@@ -679,6 +684,7 @@ ChatBot.defaultProps = {
679684
inputStyle: {},
680685
opened: undefined,
681686
placeholder: 'Type the message ...',
687+
inputAttributes: {},
682688
recognitionEnable: false,
683689
recognitionLang: 'en',
684690
recognitionPlaceholder: 'Listening ...',

lib/schemas/customSchema.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,9 @@ export default [
5959
types: ['object'],
6060
required: false,
6161
},
62+
{
63+
key: 'inputAttributes',
64+
types: ['object'],
65+
required: false,
66+
},
6267
];

lib/schemas/optionsSchema.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,9 @@ export default [
2929
types: ['object'],
3030
required: false,
3131
},
32+
{
33+
key: 'inputAttributes',
34+
types: ['object'],
35+
required: false,
36+
},
3237
];

lib/schemas/textSchema.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,9 @@ export default [
4444
types: ['object'],
4545
required: false,
4646
},
47+
{
48+
key: 'inputAttributes',
49+
types: ['object'],
50+
required: false,
51+
},
4752
];

lib/schemas/updateSchema.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,9 @@ export default [
2424
types: ['object'],
2525
required: false,
2626
},
27+
{
28+
key: 'inputAttributes',
29+
types: ['object'],
30+
required: false,
31+
},
2732
];

lib/schemas/userSchema.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,9 @@ export default [
3434
types: ['object'],
3535
required: false,
3636
},
37+
{
38+
key: 'inputAttributes',
39+
types: ['object'],
40+
required: false,
41+
},
3742
];

tests/lib/ChatBot.spec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,4 +335,25 @@ describe('ChatBot', () => {
335335
expect(step2Bubble.text()).to.be.equal('Hello World');
336336
});
337337
});
338+
339+
describe('Input Attributes', () => {
340+
const wrapper = mount(
341+
<ChatBot
342+
steps={[
343+
{
344+
id: '1',
345+
message: 'Hide Input',
346+
inputAttributes: {
347+
autoComplete: 'firstname',
348+
},
349+
end: true,
350+
},
351+
]}
352+
/>,
353+
);
354+
355+
it('should be rendered with input to autocomplete on \'firstname\'', () => {
356+
expect(wrapper.find('input.rsc-input').props().autoComplete).to.be.equal('firstname');
357+
});
358+
});
338359
});

tests/lib/schema.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,20 @@ describe('schema', () => {
102102
schema.checkInvalidIds(steps);
103103
}).to.not.throw();
104104
});
105+
it('should not throw error with metadata', () => {
106+
const step = { id: '1', message: 'Test', metadata: { data: 'test' } };
107+
expect(() => {
108+
schema.parse(step);
109+
}).to.not.throw();
110+
const resultStep = schema.parse(step);
111+
expect(resultStep).to.be.equal(step);
112+
});
113+
it('should not throw error with inputAttributes', () => {
114+
const step = { id: '1', message: 'Test', inputAttributes: { autoComplete: 'firstname' } };
115+
expect(() => {
116+
schema.parse(step);
117+
}).to.not.throw();
118+
const resultStep = schema.parse(step);
119+
expect(resultStep).to.be.equal(step);
120+
});
105121
});

0 commit comments

Comments
 (0)