Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ feat(select): ajout exemple <optgroup> [DS-3374] #734

Merged
merged 2 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/component/select/example/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@
<%- sample('Liste déroulante valide', './sample/select', {select: { id:'select-valid', valid: true}}, true); %>

<%- sample('Liste déroulante erreur', './sample/select', {select: { id:'select-error', error: true}}, true); %>

<%- sample('Liste déroulante avec groupe d\'options', './sample/option-group', {select: { id:'select-group'}}, true); %>
30 changes: 30 additions & 0 deletions src/component/select/example/sample/option-group.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<%
let select = locals.select || {};
select.valid = validData(select.valid);
select.error = errorData(select.error);
select.hint = hintData(select.hint);
select.placeholder = select.placeholder || 'Selectionnez une option';
select.label = select.label || 'Label pour liste déroulante';
select.optionGroups = [
{
label: 'Groupe 1',
options: [
{value:'1', label:'Option 1'},
{value:'2', label:'Option 2'},
{value:'3', label:'Option 3'},
{value:'4', label:'Option 4'}
]
},
{
label: 'Groupe 2',
options: [
{value:'5', label:'Option 5'},
{value:'6', label:'Option 6'},
{value:'7', label:'Option 7'},
]
}
];
%>

<%- include('../../template/ejs/select-group', {select: select}); %>
34 changes: 28 additions & 6 deletions src/component/select/template/ejs/select.ejs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ajouter la doc du param optionGroups en haut

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c'est fait merci

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
* select.label (string, required) : label
* select.options (array, required) : options du select, un array d'objets avec :
* select.optionGroups (array) : groupes d'options du select, un array d'objets avec :
* label : label du groupe d'options
* options (array) : options du select, un array d'objets avec :
* value : attribut value de l'option
* label : label de l'option
* select.options (array) : options du select, un array d'objets avec :
* value : attribut value de l'option
* label : label de l'option
Expand Down Expand Up @@ -77,11 +83,27 @@ if (select.disabled === true) attributes['disabled'] = '';
<option value="" selected disabled hidden><%= select.placeholder %></option>
<% } %>
<%
for (let i = 0; i < select.options.length; i++) {
let option = select.options[i];
%>
<option value="<%= option.value %>"><%= option.label %></option>
<% if (select.optionGroups != undefined) { %>
<%
for (let i = 0; i < select.optionGroups.length; i++) {
let optionGroup = select.optionGroups[i];
%>
<optgroup label="<%= optionGroup.label %>">
<%
for (let i = 0; i < optionGroup.options.length; i++) {
let option = optionGroup.options[i];
%>
<option value="<%= option.value %>"><%= option.label %></option>
<% } %>
</optgroup>
<% } %>
<% } else { %>
<%
for (let i = 0; i < select.options.length; i++) {
let option = select.options[i];
%>
<option value="<%= option.value %>"><%= option.label %></option>
<% } %>
<% } %>
</select>
Expand Down