Skip to content

Commit

Permalink
Fix primefaces#7439: Refactor multiselect (primefaces#7386)
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware authored Nov 3, 2024
1 parent ed35767 commit 8064529
Showing 1 changed file with 39 additions and 39 deletions.
78 changes: 39 additions & 39 deletions components/lib/multiselect/MultiSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -858,23 +858,6 @@ export const MultiSelect = React.memo(
return ObjectUtils.getJSXElement(props.selectedItemTemplate);
}

const onRemoveTokenIconKeyDown = (event, val) => {
event.preventDefault();
event.stopPropagation();

switch (event.code) {
case 'Space':
case 'NumpadEnter':
case 'Enter':
if (props.inline) {
break;
}

removeChip(event, val);
break;
}
};

if (props.display === 'chip' && !empty) {
const value = props.value.slice(0, props.maxSelectedLabels || props.value.length);

Expand All @@ -889,11 +872,11 @@ export const MultiSelect = React.memo(
const labelKey = label + '_' + i;
const iconProps = mergeProps(
{
'aria-label': localeOption('removeTokenIcon'),
className: cx('removeTokenIcon'),
onClick: (e) => removeChip(e, val),
onKeyDown: (e) => onRemoveTokenIconKeyDown(e, val),
tabIndex: props.tabIndex || '0',
'aria-label': localeOption('removeTokenIcon')
tabIndex: props.tabIndex || '0'
},
ptm('removeTokenIcon', context)
);
Expand Down Expand Up @@ -964,6 +947,40 @@ export const MultiSelect = React.memo(
}, []);
};

const onClearIconKeyDown = (event) => {
event.preventDefault();
event.stopPropagation();

switch (event.code) {
case 'Space':
case 'NumpadEnter':
case 'Enter':
if (props.inline) {
break;
}

updateModel(event, [], []);
break;
}
};

const onRemoveTokenIconKeyDown = (event, val) => {
event.preventDefault();
event.stopPropagation();

switch (event.code) {
case 'Space':
case 'NumpadEnter':
case 'Enter':
if (props.inline) {
break;
}

removeChip(event, val);
break;
}
};

React.useImperativeHandle(ref, () => ({
props,
show,
Expand Down Expand Up @@ -1001,31 +1018,14 @@ export const MultiSelect = React.memo(
ZIndexUtils.clear(overlayRef.current);
});

const onClearIconKeyDown = (event) => {
event.preventDefault();
event.stopPropagation();

switch (event.code) {
case 'Space':
case 'NumpadEnter':
case 'Enter':
if (props.inline) {
break;
}

updateModel(event, [], []);
break;
}
};

const createClearIcon = () => {
const clearIconProps = mergeProps(
{
className: cx('clearIcon'),
onClick: (e) => updateModel(e, [], []),
tabIndex: props.tabIndex || '0',
'aria-label': localeOption('clear'),
onKeyDown: (e) => onClearIconKeyDown(e)
onClick: (e) => updateModel(e, [], []),
onKeyDown: (e) => onClearIconKeyDown(e),
tabIndex: props.tabIndex || '0'
},
ptm('clearIcon')
);
Expand Down

0 comments on commit 8064529

Please sign in to comment.